Skip to content

Commit 0823f5f

Browse files
authored
codegen: Fix errant database/sql imports (#789)
* codegen: Fix errant database/sql imports Map return type of void to interface{}, not sql.NullBool * remove debug * actually test the import fix
1 parent 9b12e81 commit 0823f5f

File tree

7 files changed

+74
-10
lines changed

7 files changed

+74
-10
lines changed

internal/codegen/golang/postgresql_type.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ func postgresType(r *compiler.Result, col *compiler.Column, settings config.Comb
129129
return "sql.NullInt64"
130130

131131
case "void":
132-
// A void value always returns NULL. Since there is no built-in NULL
133-
// value into the SQL package, we'll use sql.NullBool
134-
return "sql.NullBool"
132+
// A void value can only be scanned into an empty interface.
133+
return "interface{}"
135134

136135
case "any":
137136
return "interface{}"

internal/codegen/golang/query.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package golang
22

3-
import "strings"
3+
import (
4+
"strings"
5+
6+
"github.com/kyleconroy/sqlc/internal/metadata"
7+
)
48

59
type QueryValue struct {
610
Emit bool
@@ -103,5 +107,6 @@ type Query struct {
103107
}
104108

105109
func (q Query) hasRetType() bool {
106-
return q.Cmd != ":exec" && !q.Ret.isEmpty()
110+
scanned := q.Cmd == metadata.CmdOne || q.Cmd == metadata.CmdMany
111+
return scanned && !q.Ret.isEmpty()
107112
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- name: AdvisoryLockExec :exec
2+
SELECT pg_advisory_lock($1);
3+
4+
-- name: AdvisoryLockExecRows :execrows
5+
SELECT pg_advisory_lock($1);

internal/endtoend/testdata/pg_advisory_xact_lock/go/exec.sql.go

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

internal/endtoend/testdata/pg_advisory_xact_lock/go/query.sql.go

Lines changed: 23 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
-- name: AdvisoryLock :many
1+
-- name: AdvisoryLockOne :one
2+
SELECT pg_advisory_lock($1);
3+
4+
-- name: AdvisoryUnlock :many
25
SELECT pg_advisory_unlock($1);
6+
7+
-- name: AdvisoryLockExecResult :execresult
8+
SELECT pg_advisory_lock($1);

internal/endtoend/testdata/pg_advisory_xact_lock/sqlc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"path": "go",
66
"name": "querytest",
77
"schema": "query.sql",
8-
"queries": "query.sql"
8+
"queries": ["query.sql", "exec.sql"]
99
}
1010
]
1111
}

0 commit comments

Comments
 (0)