Skip to content
Open
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
17 changes: 17 additions & 0 deletions internal/codegen/golang/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,24 @@ func (i *importer) queryImports(filename string) fileImports {
}
if !q.Arg.isEmpty() {
if q.Arg.IsStruct() {
// A single named parameter referenced as both a regular
// argument (e.g. `sqlc.narg(x) IS NULL`) and as a
// `sqlc.slice('x')` produces two struct fields sharing
// the same name and type, but only the slice variant
// carries the IsSqlcSlice flag. The non-slice duplicate
// must not be counted as a `[]T` arg requiring lib/pq,
// because the generated code expands the slice in-place
// via `/*SLICE:...*/?` and never calls pq.Array on it.
sqlcSliceNames := map[string]struct{}{}
for _, f := range q.Arg.Struct.Fields {
if f.HasSqlcSlice() {
sqlcSliceNames[f.Name] = struct{}{}
}
}
for _, f := range q.Arg.Struct.Fields {
if _, ok := sqlcSliceNames[f.Name]; ok {
continue
}
if strings.HasPrefix(f.Type, "[]") && f.Type != "[]byte" && !f.HasSqlcSlice() {
return true
}
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.

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
@@ -0,0 +1,10 @@
-- https://github.com/sqlc-dev/sqlc/issues/3783
-- name: CausesPgToBeImported :many
SELECT
id AS author_id,
name AS author_name,
bio AS author_bio
FROM
authors
WHERE
(sqlc.narg('author_ids') IS NULL OR id IN (sqlc.slice('author_ids')));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE authors (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name text NOT NULL,
bio text
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"engine": "mysql",
"path": "go",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
Loading