Skip to content

Commit

Permalink
fix(postgresql): Remove extra newline with db argument (#1417)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rliebz committed Feb 8, 2022
1 parent c8926c2 commit 5ec0caa
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/codegen/golang/templates/pgx/queryCode.tmpl
Expand Up @@ -24,7 +24,7 @@ type {{.Ret.Type}} struct { {{- range .Ret.Struct.Fields}}
{{if eq .Cmd ":one"}}
{{range .Comments}}//{{.}}
{{end -}}
{{- if $.EmitMethodsWithDBArgument}}
{{- if $.EmitMethodsWithDBArgument -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ({{.Ret.DefineType}}, error) {
row := db.QueryRow(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{- else -}}
Expand All @@ -40,7 +40,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ({{.Ret.De
{{if eq .Cmd ":many"}}
{{range .Comments}}//{{.}}
{{end -}}
{{- if $.EmitMethodsWithDBArgument}}
{{- if $.EmitMethodsWithDBArgument -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error) {
rows, err := db.Query(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{- else -}}
Expand Down Expand Up @@ -73,7 +73,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) ([]{{.Ret.
{{if eq .Cmd ":exec"}}
{{range .Comments}}//{{.}}
{{end -}}
{{- if $.EmitMethodsWithDBArgument}}
{{- if $.EmitMethodsWithDBArgument -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) error {
_, err := db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{- else -}}
Expand All @@ -87,7 +87,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) error {
{{if eq .Cmd ":execrows"}}
{{range .Comments}}//{{.}}
{{end -}}
{{if $.EmitMethodsWithDBArgument}}
{{if $.EmitMethodsWithDBArgument -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (int64, error) {
result, err := db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{- else -}}
Expand All @@ -104,7 +104,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, er
{{if eq .Cmd ":execresult"}}
{{range .Comments}}//{{.}}
{{end -}}
{{- if $.EmitMethodsWithDBArgument}}
{{- if $.EmitMethodsWithDBArgument -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (pgconn.CommandTag, error) {
return db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{- else -}}
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.

@@ -0,0 +1,23 @@
CREATE TABLE foo (
bar text
);

-- name: ManyFoo :many
-- This function returns a list of Foos
SELECT * FROM foo;

-- name: OneFoo :one
-- This function returns one Foo
SELECT * FROM foo;

-- name: ExecFoo :exec
-- This function creates a Foo via :exec
INSERT INTO foo (bar) VALUES ("bar");

-- name: ExecRowFoo :execrows
-- This function creates a Foo via :execrows
INSERT INTO foo (bar) VALUES ("bar");

-- name: ExecResultFoo :execresult
-- This function creates a Foo via :execresult
INSERT INTO foo (bar) VALUES ("bar");
@@ -0,0 +1,14 @@
{
"version": "1",
"packages": [
{
"path": "go",
"name": "querytest",
"engine": "postgresql",
"schema": "query.sql",
"queries": "query.sql",
"sql_package": "pgx/v4",
"emit_methods_with_db_argument": true
}
]
}

0 comments on commit 5ec0caa

Please sign in to comment.