Skip to content

Commit ce95162

Browse files
fix(codegen/golang): Don't import "strings" for sqlc.slice() with pgx (#3073)
Also fix the invalid test that should have caught this Resolves #3065
1 parent f0184bc commit ce95162

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

internal/codegen/golang/imports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func (i *importer) queryImports(filename string) fileImports {
390390
}
391391

392392
sqlpkg := parseDriver(i.Options.SqlPackage)
393-
if sqlcSliceScan() {
393+
if sqlcSliceScan() && !sqlpkg.IsPGX() {
394394
std["strings"] = struct{}{}
395395
}
396396
if sliceScan() && !sqlpkg.IsPGX() {

internal/endtoend/testdata/sqlc_slice/postgresql/pgx/go/models.go

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

internal/endtoend/testdata/sqlc_slice/postgresql/pgx/go/query.sql.go

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
-- name: FuncParamIdent :many
2-
SELECT name FROM foo WHERE name = sqlc.arg(slug);
2+
SELECT name FROM foo WHERE name = sqlc.arg(slug)
3+
AND id IN (sqlc.slice(favourites));
34

45
-- name: FuncParamString :many
5-
SELECT name FROM foo WHERE name = sqlc.arg('slug');
6+
SELECT name FROM foo WHERE name = sqlc.arg('slug')
7+
AND id IN (sqlc.slice('favourites'));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
CREATE TABLE foo (name text not null);
1+
CREATE TABLE foo (id int not null, name text not null);
22

0 commit comments

Comments
 (0)