Skip to content

Commit af71d50

Browse files
committed
codegen/golang: emit any instead of interface{}
Generated Go code now uses the predeclared any alias everywhere the generator previously wrote interface{}, so running go fix over generated packages produces no changes (#4470). - Replace interface{} with any in the Go type mappers (postgresql, mysql, sqlite, unknown-engine fallback), the stdlib and pgx templates, and the enum Scan methods. - Reserve the identifier any and escape query constant names: a query named Any used to generate 'const any = ...', which shadows the predeclared any type package-wide and now would break compilation; it generates 'const any_ = ...' instead. - Regenerate all endtoend golden files and examples, update the diff and expected-failure fixtures that generation does not overwrite, and update the generated-code samples in docs/howto. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pq9Cgx285AU4NZpCYgtkYS
1 parent d72f916 commit af71d50

1,047 files changed

Lines changed: 3136 additions & 3132 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.

docs/howto/delete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
type DBTX interface {
33-
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
33+
ExecContext(context.Context, string, ...any) (sql.Result, error)
3434
}
3535

3636
func New(db DBTX) *Queries {

docs/howto/insert.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
type DBTX interface {
33-
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
33+
ExecContext(context.Context, string, ...any) (sql.Result, error)
3434
}
3535

3636
func New(db DBTX) *Queries {

docs/howto/prepared_query.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Record struct {
3535

3636
type DBTX interface {
3737
PrepareContext(context.Context, string) (*sql.Stmt, error)
38-
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
38+
QueryRowContext(context.Context, string, ...any) *sql.Row
3939
}
4040

4141
func New(db DBTX) *Queries {
@@ -51,7 +51,7 @@ func Prepare(ctx context.Context, db DBTX) (*Queries, error) {
5151
return &q, nil
5252
}
5353

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

docs/howto/query_count.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
)
2525

2626
type DBTX interface {
27-
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
28-
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
27+
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
28+
QueryRowContext(context.Context, string, ...any) *sql.Row
2929
}
3030

3131
func New(db DBTX) *Queries {

docs/howto/select.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ type Author struct {
6969
}
7070

7171
type DBTX interface {
72-
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
73-
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
72+
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
73+
QueryRowContext(context.Context, string, ...any) *sql.Row
7474
}
7575

7676
func New(db DBTX) *Queries {
@@ -161,7 +161,7 @@ import (
161161
)
162162

163163
type DBTX interface {
164-
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
164+
QueryRowContext(context.Context, string, ...any) *sql.Row
165165
}
166166

167167
func New(db DBTX) *Queries {
@@ -243,8 +243,8 @@ type Author struct {
243243
}
244244

245245
type DBTX interface {
246-
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
247-
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
246+
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
247+
QueryRowContext(context.Context, string, ...any) *sql.Row
248248
}
249249

250250
func New(db DBTX) *Queries {
@@ -334,10 +334,10 @@ type Author struct {
334334
}
335335

336336
type DBTX interface {
337-
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
337+
ExecContext(context.Context, string, ...any) (sql.Result, error)
338338
PrepareContext(context.Context, string) (*sql.Stmt, error)
339-
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
340-
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
339+
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
340+
QueryRowContext(context.Context, string, ...any) *sql.Row
341341
}
342342

343343
func New(db DBTX) *Queries {
@@ -361,7 +361,7 @@ WHERE id IN (/*SLICE:ids*/?)
361361

362362
func (q *Queries) ListAuthorsByIDs(ctx context.Context, ids []int64) ([]Author, error) {
363363
sql := listAuthorsByIDs
364-
var queryParams []interface{}
364+
var queryParams []any
365365
if len(ids) == 0 {
366366
return nil, fmt.Errorf("slice ids must have at least one element")
367367
}

docs/howto/transactions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ import (
3232
)
3333

3434
type DBTX interface {
35-
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
35+
ExecContext(context.Context, string, ...any) (sql.Result, error)
3636
PrepareContext(context.Context, string) (*sql.Stmt, error)
37-
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
38-
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
37+
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
38+
QueryRowContext(context.Context, string, ...any) *sql.Row
3939
}
4040

4141
func New(db DBTX) *Queries {

docs/howto/update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
)
3636

3737
type DBTX interface {
38-
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
38+
ExecContext(context.Context, string, ...any) (sql.Result, error)
3939
}
4040

4141
func New(db DBTX) *Queries {
@@ -86,7 +86,7 @@ import (
8686
)
8787

8888
type DBTX interface {
89-
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
89+
ExecContext(context.Context, string, ...any) (sql.Result, error)
9090
}
9191

9292
func New(db DBTX) *Queries {

examples/authors/mysql/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.

examples/authors/postgresql/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.

examples/authors/sqlite/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.

0 commit comments

Comments
 (0)