Skip to content

Commit 190c069

Browse files
chore: replace interface{} with any in Go/SQLite code generation
Replaces all auto-generated interface{} with any in Go/SQLite code generation templates and type mapping functions. This is the modern Go idiom since Go 1.18 (any is a built-in alias for interface{}). Changes: - sqlite_type.go: return 'any' instead of 'interface{}' for SQLite 'any' type and unknown type default case - go_type.go: return 'any' instead of 'interface{}' for unknown engine default case - result.go: update type comparison from 'interface{}' to 'any' - template.tmpl: Scan() methods use 'any' parameter type - stdlib/queryCode.tmpl: use '[]any' instead of '[]interface{}' - stdlib/dbCode.tmpl: DBTX interface and helpers use '...any' - Update all SQLite endtoend test golden files Signed-off-by: Md Mushfiqur Rahim <20mahin2020@gmail.com>
1 parent ecec179 commit 190c069

103 files changed

Lines changed: 325 additions & 325 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/codegen/golang/go_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ func goInnerType(req *plugin.GenerateRequest, options *opts.Options, col *plugin
8787
case "sqlite":
8888
return sqliteType(req, options, col)
8989
default:
90-
return "interface{}"
90+
return "any"
9191
}
9292
}

internal/codegen/golang/result.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func columnsToStruct(req *plugin.GenerateRequest, options *opts.Options, name st
438438
// field with the same name has a known type, assign
439439
// the known type to the field without a known type
440440
for i, field := range gs.Fields {
441-
if len(seen[field.Name]) > 1 && field.Type == "interface{}" {
441+
if len(seen[field.Name]) > 1 && field.Type == "any" {
442442
for _, j := range seen[field.Name] {
443443
if i == j {
444444
continue

internal/codegen/golang/sqlite_type.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func sqliteType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.
6060
return "json.RawMessage"
6161

6262
case "any":
63-
return "interface{}"
63+
return "any"
6464

6565
}
6666

@@ -96,7 +96,7 @@ func sqliteType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.
9696
log.Printf("unknown SQLite type: %s\n", dt)
9797
}
9898

99-
return "interface{}"
99+
return "any"
100100

101101
}
102102
}

internal/codegen/golang/templates/stdlib/dbCode.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{{define "dbCodeTemplateStd"}}
22
type DBTX interface {
3-
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
3+
ExecContext(context.Context, string, ...any) (sql.Result, error)
44
PrepareContext(context.Context, string) (*sql.Stmt, error)
5-
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
6-
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
5+
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
6+
QueryRowContext(context.Context, string, ...any) *sql.Row
77
}
88

99
{{ if .EmitMethodsWithDBArgument}}
@@ -42,7 +42,7 @@ func (q *Queries) Close() error {
4242
return err
4343
}
4444

45-
func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (sql.Result, error) {
45+
func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args ...any) (sql.Result, error) {
4646
switch {
4747
case stmt != nil && q.tx != nil:
4848
return q.tx.StmtContext(ctx, stmt).ExecContext(ctx, args...)
@@ -53,7 +53,7 @@ func (q *Queries) exec(ctx context.Context, stmt *sql.Stmt, query string, args .
5353
}
5454
}
5555

56-
func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Rows, error) {
56+
func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args ...any) (*sql.Rows, error) {
5757
switch {
5858
case stmt != nil && q.tx != nil:
5959
return q.tx.StmtContext(ctx, stmt).QueryContext(ctx, args...)
@@ -64,7 +64,7 @@ func (q *Queries) query(ctx context.Context, stmt *sql.Stmt, query string, args
6464
}
6565
}
6666

67-
func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...interface{}) (*sql.Row) {
67+
func (q *Queries) queryRow(ctx context.Context, stmt *sql.Stmt, query string, args ...any) (*sql.Row) {
6868
switch {
6969
case stmt != nil && q.tx != nil:
7070
return q.tx.StmtContext(ctx, stmt).QueryRowContext(ctx, args...)

internal/codegen/golang/templates/stdlib/queryCode.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
127127
{{define "queryCodeStdExec"}}
128128
{{- if .Arg.HasSqlcSlices }}
129129
query := {{.ConstantName}}
130-
var queryParams []interface{}
130+
var queryParams []any
131131
{{- if .Arg.Struct }}
132132
{{- $arg := .Arg }}
133133
{{- range .Arg.Struct.Fields }}

internal/codegen/golang/templates/template.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const (
9696
{{- end}}
9797
)
9898

99-
func (e *{{.Name}}) Scan(src interface{}) error {
99+
func (e *{{.Name}}) Scan(src any) error {
100100
switch s := src.(type) {
101101
case []byte:
102102
*e = {{.Name}}(s)
@@ -114,7 +114,7 @@ type Null{{.Name}} struct {
114114
}
115115

116116
// Scan implements the Scanner interface.
117-
func (ns *Null{{.Name}}) Scan(value interface{}) error {
117+
func (ns *Null{{.Name}}) Scan(value any) error {
118118
if value == nil {
119119
ns.{{.Name}}, ns.Valid = "", false
120120
return nil

internal/endtoend/testdata/accurate_sqlite/sqlite/stdlib/go/db.go

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

internal/endtoend/testdata/alias/sqlite/go/db.go

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

internal/endtoend/testdata/between_args/sqlite/go/db.go

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

internal/endtoend/testdata/builtins/sqlite/go/aggfunc.sql.go

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

0 commit comments

Comments
 (0)