Skip to content

Commit

Permalink
fix(codegen/golang): Don't import "strings" for sqlc.slice() with…
Browse files Browse the repository at this point in the history
… pgx (#3073)

Also fix the invalid test that should have caught this

Resolves #3065
  • Loading branch information
andrewmbenton authored Dec 20, 2023
1 parent f0184bc commit ce95162
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/codegen/golang/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (i *importer) queryImports(filename string) fileImports {
}

sqlpkg := parseDriver(i.Options.SqlPackage)
if sqlcSliceScan() {
if sqlcSliceScan() && !sqlpkg.IsPGX() {
std["strings"] = struct{}{}
}
if sliceScan() && !sqlpkg.IsPGX() {
Expand Down

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

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

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- name: FuncParamIdent :many
SELECT name FROM foo WHERE name = sqlc.arg(slug);
SELECT name FROM foo WHERE name = sqlc.arg(slug)
AND id IN (sqlc.slice(favourites));

-- name: FuncParamString :many
SELECT name FROM foo WHERE name = sqlc.arg('slug');
SELECT name FROM foo WHERE name = sqlc.arg('slug')
AND id IN (sqlc.slice('favourites'));
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CREATE TABLE foo (name text not null);
CREATE TABLE foo (id int not null, name text not null);

0 comments on commit ce95162

Please # to comment.