Skip to content

Commit

Permalink
Add single query preparation
Browse files Browse the repository at this point in the history
Fixes #2905
  • Loading branch information
darkfeline committed Jan 15, 2024
1 parent b4f03e9 commit dede0ce
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/codegen/golang/templates/stdlib/dbCode.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ type Queries struct {
{{- end}}
{{- end}}
}
{{if .EmitPreparedQueries -}}
{{range .GoQueries}}

func (q *Queries) Prepare{{.MethodName}}(ctx context.Context) error {
var err error
if q.{{.FieldName}}, err = q.db.PrepareContext(ctx, {{.ConstantName}}); err != nil {
return fmt.Errorf("error preparing query {{.MethodName}}: %w", err)
}
return nil
}
{{- end}}
{{- end}}

{{if not .EmitMethodsWithDBArgument}}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
Expand Down

0 comments on commit dede0ce

Please sign in to comment.