Skip to content

Commit 647b650

Browse files
authored
update stdlib db template with BeginTx
1 parent 7f4bbfd commit 647b650

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/codegen/golang/templates/stdlib/dbCode.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{define "dbCodeTemplateStd"}}
22
type DBTX interface {
3+
BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
34
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
45
PrepareContext(context.Context, string) (*sql.Stmt, error)
56
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
@@ -101,5 +102,12 @@ func (q *Queries) WithTx(tx *sql.Tx) *Queries {
101102
{{- end}}
102103
}
103104
}
105+
func (q *Queries) BeginTx(ctx context.Context, opts driver.TxOptions) (*Queries, error) {
106+
tx, err := q.db.BeginTx(ctx, opts)
107+
if (err != nil {
108+
return nil, err
109+
}
110+
return q.WithTx(tx), nil
111+
}
104112
{{end}}
105113
{{end}}

0 commit comments

Comments
 (0)