Skip to content

Commit 6eaf60c

Browse files
committed
fix: pgx closed batch return pointer if need #1959
1 parent 3623ec8 commit 6eaf60c

File tree

15 files changed

+227
-4
lines changed

15 files changed

+227
-4
lines changed

internal/codegen/golang/templates/pgx/batchCode.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (b *{{.MethodName}}BatchResults) QueryRow(f func(int, {{.Ret.DefineType}},
107107
var {{.Ret.Name}} {{.Ret.Type}}
108108
if b.closed {
109109
if f != nil {
110-
f(t, {{.Ret.Name}}, errors.New("batch already closed"))
110+
f(t, {{if .Ret.IsPointer}}nil{{else}}{{.Ret.Name}}{{end}}, errors.New("batch already closed"))
111111
}
112112
continue
113113
}

internal/endtoend/testdata/emit_result_and_params_struct_pointers/postgresql/pgx/v4/go/batch.go

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

internal/endtoend/testdata/emit_result_and_params_struct_pointers/postgresql/pgx/v4/go/db.go

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

internal/endtoend/testdata/emit_result_and_params_struct_pointers/postgresql/pgx/v4/go/models.go

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

internal/endtoend/testdata/emit_result_and_params_struct_pointers/postgresql/pgx/v4/go/query.sql.go

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE TABLE foo (a integer, b integer);
2+
3+
-- name: InsertValues :batchone
4+
INSERT INTO foo (a, b)
5+
VALUES ($1, $2)
6+
ON CONFLICT DO NOTHING
7+
RETURNING *;
8+
9+
-- name: GetOne :one
10+
SELECT * FROM foo WHERE a = ? AND b = ? LIMIT 1;
11+
12+
-- name: GetAll :many
13+
SELECT * FROM foo;
14+
15+
-- name: GetAllAByB :many
16+
SELECT a FROM foo WHERE b = ?;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "2",
3+
"sql": [
4+
{
5+
"engine": "postgresql",
6+
"schema": "query.sql",
7+
"queries": "query.sql",
8+
"gen": {
9+
"go": {
10+
"package": "querytest",
11+
"sql_package": "pgx/v4",
12+
"out": "go",
13+
"emit_result_struct_pointers": true,
14+
"emit_params_struct_pointers": true
15+
}
16+
}
17+
}
18+
]
19+
}

internal/endtoend/testdata/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904
1111
github.com/kyleconroy/sqlc-testdata v0.0.0-20200512000015-15313bc43553
1212
github.com/lib/pq v1.9.0
13-
github.com/tabbed/pqtype v0.1.0 // indirect
13+
github.com/tabbed/pqtype v0.1.0
1414
github.com/volatiletech/null/v8 v8.1.2
1515
gopkg.in/guregu/null.v4 v4.0.0
1616
)

internal/endtoend/testdata/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx
1414
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
1515
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
1616
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
17-
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
18-
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1917
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
2018
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2119
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=

0 commit comments

Comments
 (0)