Skip to content

Commit 5ec0caa

Browse files
authored
fix(postgresql): Remove extra newline with db argument (#1417)
The original fix (#1395) for #1393 did not cover the case where `emit_methods_with_db_argument` was set to `true`. This follows the same pattern to handle that case as well.
1 parent c8926c2 commit 5ec0caa

File tree

6 files changed

+156
-5
lines changed

6 files changed

+156
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type {{.Ret.Type}} struct { {{- range .Ret.Struct.Fields}}
2424
{{if eq .Cmd ":one"}}
2525
{{range .Comments}}//{{.}}
2626
{{end -}}
27-
{{- if $.EmitMethodsWithDBArgument}}
27+
{{- if $.EmitMethodsWithDBArgument -}}
2828
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error) {
2929
row := db.QueryRow(ctx, {{.ConstantName}}, {{.Arg.Params}})
3030
{{- else -}}
@@ -40,7 +40,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ({{.Ret.De
4040
{{if eq .Cmd ":many"}}
4141
{{range .Comments}}//{{.}}
4242
{{end -}}
43-
{{- if $.EmitMethodsWithDBArgument}}
43+
{{- if $.EmitMethodsWithDBArgument -}}
4444
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error) {
4545
rows, err := db.Query(ctx, {{.ConstantName}}, {{.Arg.Params}})
4646
{{- else -}}
@@ -73,7 +73,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([]{{.Ret.
7373
{{if eq .Cmd ":exec"}}
7474
{{range .Comments}}//{{.}}
7575
{{end -}}
76-
{{- if $.EmitMethodsWithDBArgument}}
76+
{{- if $.EmitMethodsWithDBArgument -}}
7777
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) error {
7878
_, err := db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
7979
{{- else -}}
@@ -87,7 +87,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) error {
8787
{{if eq .Cmd ":execrows"}}
8888
{{range .Comments}}//{{.}}
8989
{{end -}}
90-
{{if $.EmitMethodsWithDBArgument}}
90+
{{if $.EmitMethodsWithDBArgument -}}
9191
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (int64, error) {
9292
result, err := db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
9393
{{- else -}}
@@ -104,7 +104,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, er
104104
{{if eq .Cmd ":execresult"}}
105105
{{range .Comments}}//{{.}}
106106
{{end -}}
107-
{{- if $.EmitMethodsWithDBArgument}}
107+
{{- if $.EmitMethodsWithDBArgument -}}
108108
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (pgconn.CommandTag, error) {
109109
return db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
110110
{{- else -}}

internal/endtoend/testdata/comment_godoc_db_argument/postgresql/pgx/go/db.go

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

internal/endtoend/testdata/comment_godoc_db_argument/postgresql/pgx/go/models.go

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

internal/endtoend/testdata/comment_godoc_db_argument/postgresql/pgx/go/query.sql.go

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE TABLE foo (
2+
bar text
3+
);
4+
5+
-- name: ManyFoo :many
6+
-- This function returns a list of Foos
7+
SELECT * FROM foo;
8+
9+
-- name: OneFoo :one
10+
-- This function returns one Foo
11+
SELECT * FROM foo;
12+
13+
-- name: ExecFoo :exec
14+
-- This function creates a Foo via :exec
15+
INSERT INTO foo (bar) VALUES ("bar");
16+
17+
-- name: ExecRowFoo :execrows
18+
-- This function creates a Foo via :execrows
19+
INSERT INTO foo (bar) VALUES ("bar");
20+
21+
-- name: ExecResultFoo :execresult
22+
-- This function creates a Foo via :execresult
23+
INSERT INTO foo (bar) VALUES ("bar");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"name": "querytest",
7+
"engine": "postgresql",
8+
"schema": "query.sql",
9+
"queries": "query.sql",
10+
"sql_package": "pgx/v4",
11+
"emit_methods_with_db_argument": true
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)