Allow for mixed parameters types ($1 or ?) and sqlc.arg()#1072
Merged
kyleconroy merged 15 commits intosqlc-dev:mainfrom Sep 15, 2021
Merged
Allow for mixed parameters types ($1 or ?) and sqlc.arg()#1072kyleconroy merged 15 commits intosqlc-dev:mainfrom
kyleconroy merged 15 commits intosqlc-dev:mainfrom
Conversation
…nt to port from mysql
Closed
kyleconroy
reviewed
Sep 12, 2021
Collaborator
kyleconroy
left a comment
There was a problem hiding this comment.
I left a few comments, but please let me know if you're free to work on this. If not, I'll merge it as-is and clean it up.
Contributor
Author
|
I think I made the changes last night.
…On Sun, Sep 12, 2021 at 4:31 PM Kyle Conroy ***@***.***> wrote:
***@***.**** commented on this pull request.
I left a few comments, but please let me know if you're free to work on
this. If not, I'll merge it as-is and clean it up.
------------------------------
In internal/sql/validate/param_style.go
<#1072 (comment)>:
> + /*
+ if len(fc.Args.Items) != 1 {
+ return &sqlerr.Error{
+ Code: "", // TODO: Pick a new error code
+ Message: fmt.Sprintf("expected 1 parameter to sqlc.arg; got %d", len(fc.Args.Items)),
+ }
+ }
+ */
We shouldn't leave uncommented blocks of code around.
------------------------------
In internal/sql/validate/param_style.go
<#1072 (comment)>:
> - if check {
- return &sqlerr.Error{
- Code: "", // TODO: Pick a new error code
- Message: "query mixes positional parameters ($1) and named parameters (sqlc.arg or @arg)",
+ for _, f := range namedFunc.Items {
+ fc, ok := f.(*ast.FuncCall)
+ if ok {
+ /*
+ if len(fc.Args.Items) != 1 {
+ return &sqlerr.Error{
+ Code: "", // TODO: Pick a new error code
+ Message: fmt.Sprintf("expected 1 parameter to sqlc.arg; got %d", len(fc.Args.Items)),
+ }
+ }
+ */
+ switch fc.Args.Items[0].(type) {
You can use a type switch here to improve the code so you don't have to
type assert three times.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1072 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALAVUCBQYZ2V76N22PEHY3UBUZ4DANCNFSM47U4FNMQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This builds on pull request #1071. I realized there were issues when postgresql was using ? format so I added support for that format. I figure it will be useful for porting sqlc code from mysql to postgres. What I prohibit is mixed use of $1 and ? formats.