Skip to content

Commit d7b706c

Browse files
committed
fix: named params contribute to batch parameter count
1 parent 0ebe855 commit d7b706c

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

examples/batch/postgresql/batch.go

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

examples/batch/postgresql/querier.go

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

examples/batch/postgresql/query.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ WHERE author_id = $1;
66
DELETE FROM books
77
WHERE book_id = $1;
88

9+
-- name: DeleteBookNamedFunc :batchexec
10+
DELETE FROM books
11+
WHERE book_id = sqlc.arg(book_id);
12+
13+
-- name: DeleteBookNamedSign :batchexec
14+
DELETE FROM books
15+
WHERE book_id = @book_id;
16+
917
-- name: BooksByYear :batchmany
1018
SELECT * FROM books
1119
WHERE year = $1;

internal/sql/validate/cmd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66

77
"github.com/kyleconroy/sqlc/internal/metadata"
88
"github.com/kyleconroy/sqlc/internal/sql/ast"
9+
"github.com/kyleconroy/sqlc/internal/sql/astutils"
10+
"github.com/kyleconroy/sqlc/internal/sql/named"
911
)
1012

1113
func validateCopyfrom(n ast.Node) error {
@@ -45,6 +47,11 @@ func validateCopyfrom(n ast.Node) error {
4547
}
4648

4749
func validateBatch(n ast.Node) error {
50+
namedFunc := astutils.Search(n, named.IsParamFunc)
51+
namedSign := astutils.Search(n, named.IsParamSign)
52+
if len(namedFunc.Items)+len(namedSign.Items) > 0 {
53+
return nil
54+
}
4855
nums, _, _ := ParamRef(n)
4956
if len(nums) == 0 {
5057
return errors.New(":batch* commands require parameters")

0 commit comments

Comments
 (0)