From 6973ea951d564d8f07dafe2adcaba45931387e92 Mon Sep 17 00:00:00 2001 From: Alex Dulin Date: Wed, 9 Feb 2022 16:36:21 -0500 Subject: [PATCH] fix copyfrom methods on interface not matching generated methods The methods generated for `copyfrom` queries correctly define a slice of inputs on the function signatures, but the interface code that was generated did not. Thus, the interface was not usable when any query used `copyfrom`. This merge request updates the interface code template to correctly use `.Arg.SlicePair` when building the interface. Signed-off-by: Alex Dulin --- .../golang/templates/pgx/interfaceCode.tmpl | 4 ++-- .../copyfrom/postgresql/pgx/go/querier.go | 15 +++++++++++++++ .../testdata/copyfrom/postgresql/pgx/sqlc.json | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 internal/endtoend/testdata/copyfrom/postgresql/pgx/go/querier.go diff --git a/internal/codegen/golang/templates/pgx/interfaceCode.tmpl b/internal/codegen/golang/templates/pgx/interfaceCode.tmpl index 510332a0b4..c8bedb997c 100644 --- a/internal/codegen/golang/templates/pgx/interfaceCode.tmpl +++ b/internal/codegen/golang/templates/pgx/interfaceCode.tmpl @@ -28,9 +28,9 @@ {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (pgconn.CommandTag, error) {{- end}} {{- if and (eq .Cmd ":copyfrom") ($dbtxParam) }} - {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (int64, error) + {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.SlicePair}}) (int64, error) {{- else if eq .Cmd ":copyfrom" }} - {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, error) + {{.MethodName}}(ctx context.Context, {{.Arg.SlicePair}}) (int64, error) {{- end}} {{- end}} } diff --git a/internal/endtoend/testdata/copyfrom/postgresql/pgx/go/querier.go b/internal/endtoend/testdata/copyfrom/postgresql/pgx/go/querier.go new file mode 100644 index 0000000000..0e8a44f548 --- /dev/null +++ b/internal/endtoend/testdata/copyfrom/postgresql/pgx/go/querier.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. + +package querytest + +import ( + "context" + "database/sql" +) + +type Querier interface { + InsertSingleValue(ctx context.Context, a []sql.NullString) (int64, error) + InsertValues(ctx context.Context, arg []InsertValuesParams) (int64, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/endtoend/testdata/copyfrom/postgresql/pgx/sqlc.json b/internal/endtoend/testdata/copyfrom/postgresql/pgx/sqlc.json index 9403bd0279..2ec707567a 100644 --- a/internal/endtoend/testdata/copyfrom/postgresql/pgx/sqlc.json +++ b/internal/endtoend/testdata/copyfrom/postgresql/pgx/sqlc.json @@ -7,7 +7,8 @@ "sql_package": "pgx/v4", "name": "querytest", "schema": "query.sql", - "queries": "query.sql" + "queries": "query.sql", + "emit_interface": true } ] }