Skip to content

Commit 96fc379

Browse files
committed
Escape constant names in queries
The `any` keyword was introduced in Go 1.18, and can be used in place of `interface{}`. This was not in the list of reserved keywords, leading to identifiers using this term in generated code. Update the logic to escape constant names, and also add `any` to the list of reserved keywords. Signed-off-by: Prajwal Nadig <prajwalnadig21@gmail.com>
1 parent e209d86 commit 96fc379

5 files changed

Lines changed: 9 additions & 7 deletions

File tree

internal/codegen/golang/reserved.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ func escape(s string) string {
99

1010
func IsReserved(s string) bool {
1111
switch s {
12+
case "any":
13+
return true
1214
case "break":
1315
return true
1416
case "default":

internal/codegen/golang/result.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func buildQueries(req *plugin.GenerateRequest, options *opts.Options, enums []En
219219

220220
gq := Query{
221221
Cmd: query.Cmd,
222-
ConstantName: constantName,
222+
ConstantName: escape(constantName),
223223
FieldName: sdk.LowerTitle(query.Name) + "Stmt",
224224
MethodName: query.Name,
225225
SourceName: query.Filename,

internal/endtoend/testdata/any/pgx/v4/go/query.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/any/pgx/v5/go/query.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/any/stdlib/go/query.sql.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)