Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MySQL slice shadowing database/sql import #2332

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/booktest/sqlite/query.sql.go

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

12 changes: 6 additions & 6 deletions internal/codegen/golang/templates/stdlib/queryCode.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}

{{define "queryCodeStdExec"}}
{{- if .Arg.HasSqlcSlices }}
sql := {{.ConstantName}}
query := {{.ConstantName}}
var queryParams []interface{}
{{- if .Arg.Struct }}
{{- $arg := .Arg }}
Expand All @@ -130,9 +130,9 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
for _, v := range {{$arg.Name}}.{{.Name}} {
queryParams = append(queryParams, v)
}
sql = strings.Replace(sql, "/*SLICE:{{.Column.Name}}*/?", strings.Repeat(",?", len({{$arg.Name}}.{{.Name}}))[1:], 1)
query = strings.Replace(query, "/*SLICE:{{.Column.Name}}*/?", strings.Repeat(",?", len({{$arg.Name}}.{{.Name}}))[1:], 1)
} else {
sql = strings.Replace(sql, "/*SLICE:{{.Column.Name}}*/?", "NULL", 1)
query = strings.Replace(query, "/*SLICE:{{.Column.Name}}*/?", "NULL", 1)
}
{{- else }}
queryParams = append(queryParams, {{$arg.Name}}.{{.Name}})
Expand All @@ -147,12 +147,12 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
for _, v := range {{.Arg.Name}} {
queryParams = append(queryParams, v)
}
sql = strings.Replace(sql, "/*SLICE:{{.Arg.Column.Name}}*/?", strings.Repeat(",?", len({{.Arg.Name}}))[1:], 1)
query = strings.Replace(query, "/*SLICE:{{.Arg.Column.Name}}*/?", strings.Repeat(",?", len({{.Arg.Name}}))[1:], 1)
} else {
sql = strings.Replace(sql, "/*SLICE:{{.Arg.Column.Name}}*/?", "NULL", 1)
query = strings.Replace(query, "/*SLICE:{{.Arg.Column.Name}}*/?", "NULL", 1)
}
{{- end }}
{{ queryRetval . }} {{ queryMethod . }}(ctx, sql, queryParams...)
{{ queryRetval . }} {{ queryMethod . }}(ctx, query, queryParams...)
{{- else if emitPreparedQueries }}
{{- queryRetval . }} {{ queryMethod . }}(ctx, q.{{.FieldName}}, {{.ConstantName}}, {{.Arg.Params}})
{{- else}}
Expand Down
5 changes: 4 additions & 1 deletion internal/endtoend/testdata/sqlc_slice/mysql/go/models.go

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

71 changes: 55 additions & 16 deletions internal/endtoend/testdata/sqlc_slice/mysql/go/query.sql.go

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

6 changes: 5 additions & 1 deletion internal/endtoend/testdata/sqlc_slice/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE foo (id int not null, name text not null);
CREATE TABLE foo (id int not null, name text not null, bar text null);

/* name: FuncParamIdent :many */
SELECT name FROM foo
Expand All @@ -17,3 +17,7 @@ WHERE id IN (sqlc.slice('favourites'));
/* name: SliceExec :exec */
UPDATE foo SET name = sqlc.arg(slug)
WHERE id IN (sqlc.slice(favourites));

/* name: FuncNullable :many */
SELECT bar FROM foo
WHERE id IN (sqlc.slice('favourites'));
5 changes: 4 additions & 1 deletion internal/endtoend/testdata/sqlc_slice/sqlite/go/models.go

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

71 changes: 55 additions & 16 deletions internal/endtoend/testdata/sqlc_slice/sqlite/go/query.sql.go

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

6 changes: 5 additions & 1 deletion internal/endtoend/testdata/sqlc_slice/sqlite/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE foo (id int not null, name text not null);
CREATE TABLE foo (id int not null, name text not null, bar text);

/* name: FuncParamIdent :many */
SELECT name FROM foo
Expand All @@ -17,3 +17,7 @@ WHERE id IN (sqlc.slice('favourites'));
/* name: SliceExec :exec */
UPDATE foo SET name = sqlc.arg(slug)
WHERE id IN (sqlc.slice(favourites));

/* name: FuncNullable :many */
SELECT bar FROM foo
WHERE id IN (sqlc.slice('favourites'));
Loading