Skip to content

Commit

Permalink
fix: pgx closed batch return pointer if need sqlc-dev#1959
Browse files Browse the repository at this point in the history
  • Loading branch information
flymedllva committed Feb 22, 2023
1 parent c8d493b commit a8b5574
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/codegen/golang/templates/pgx/batchCode.tmpl
Expand Up @@ -107,7 +107,7 @@ func (b *{{.MethodName}}BatchResults) QueryRow(f func(int, {{.Ret.DefineType}},
var {{.Ret.Name}} {{.Ret.Type}}
if b.closed {
if f != nil {
f(t, {{.Ret.Name}}, errors.New("batch already closed"))
f(t, {{if .Ret.IsPointer}}nil{{else}}{{.Ret.Name}}{{end}}, errors.New("batch already closed"))
}
continue
}
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.

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

@@ -0,0 +1,16 @@
CREATE TABLE foo (a integer, b integer);

-- name: InsertValues :batchone
INSERT INTO foo (a, b)
VALUES ($1, $2)
ON CONFLICT DO NOTHING
RETURNING *;

-- name: GetOne :one
SELECT * FROM foo WHERE a = ? AND b = ? LIMIT 1;

-- name: GetAll :many
SELECT * FROM foo;

-- name: GetAllAByB :many
SELECT a FROM foo WHERE b = ?;
@@ -0,0 +1,19 @@
{
"version": "2",
"sql": [
{
"engine": "postgresql",
"schema": "query.sql",
"queries": "query.sql",
"gen": {
"go": {
"package": "querytest",
"sql_package": "pgx/v4",
"out": "go",
"emit_result_struct_pointers": true,
"emit_params_struct_pointers": true
}
}
}
]
}

0 comments on commit a8b5574

Please sign in to comment.