Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: escape constant names in queries
Also adds `any` as a reserved keyword, as it was introduced in Go 1.18.

Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
  • Loading branch information
snprajwal committed May 13, 2025
commit 03343f1cba15f56ad5216350afe0ed3727e95f70
2 changes: 2 additions & 0 deletions internal/codegen/golang/reserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ func escape(s string) string {

func IsReserved(s string) bool {
switch s {
case "any":
return true
case "break":
return true
case "default":
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs []

gq := Query{
Cmd: query.Cmd,
ConstantName: constantName,
ConstantName: escape(constantName),
FieldName: sdk.LowerTitle(query.Name) + "Stmt",
MethodName: query.Name,
SourceName: query.Filename,
Expand Down
4 changes: 2 additions & 2 deletions internal/endtoend/testdata/any/pgx/v4/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/endtoend/testdata/any/pgx/v5/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/endtoend/testdata/any/stdlib/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.