8000 feat(codegen/golang): add an option to wrap query errors that includes query name by andrewmbenton · Pull Request #3876 · sqlc-dev/sqlc · GitHub
[go: up one dir, main page]

Skip to content

feat(codegen/golang): add an option to wrap query errors that includes query name #3876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files 8000 .
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use queryretval template func to avoid rewriting test output
  • Loading branch information
andrewmbenton committed Mar 9, 2025
commit f2200867c762fb45b62c11be5389d287c28870e5
6 changes: 3 additions & 3 deletions internal/codegen/golang/templates/pgx/queryCode.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, er
{{end -}}
{{- if $.EmitMethodsWithDBArgument -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, db DBTX, {{.Arg.Pair}}) (pgconn.CommandTag, error) {
result, err := db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{queryRetval .}} db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{- else -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (pgconn.CommandTag, error) {
result, err := q.db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{queryRetval .}} q.db.Exec(ctx, {{.ConstantName}}, {{.Arg.Params}})
{{- end}}
{{- if $.WrapErrors}}
if err != nil {
err = fmt.Errorf("error executing query {{.MethodName}}: %w", err)
}
{{- end}}
return result, err
{{- end}}
}
{{end}}

Expand Down
Loading
0