forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbCode.tmpl
More file actions
57 lines (53 loc) · 1.37 KB
/
dbCode.tmpl
File metadata and controls
57 lines (53 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{{define "dbCodeTemplatePgx"}}
type DBTX interface {
{{- if .EmitBegin }}
Begin(context.Context) (pgx.Tx, error)
BeginTx(context.Context, txOptions TxOptions) (pgx.Tx, error)
{{- end }}
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
{{- if .UsesCopyFrom }}
CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
{{- end }}
{{- if .UsesBatch }}
SendBatch(context.Context, *pgx.Batch) pgx.BatchResults
{{- end }}
}
{{ if .EmitMethodsWithDBArgument}}
func New() *Queries {
return &Queries{}
{{- else -}}
func New(db DBTX) *Queries {
return &Queries{db: db}
{{- end}}
}
type Queries struct {
{{if not .EmitMethodsWithDBArgument}}
db DBTX
{{end}}
}
{{if not .EmitMethodsWithDBArgument}}
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
return &Queries{
db: tx,
}
}
{{- if .EmitBegin }}
func (q *Queries) Begin(ctx context.Context) (*Queries, error) {
tx, err := q.db.Begin(ctx)
if (err != nil {
return nil, err
}
return q.WithTx(tx), nil
}
func (q *Queries) BeginTx(ctx context.Context, txOptions TxOptions) (*Queries, error) {
tx, err := q.db.BeginTx(ctx, txOptions)
if (err != nil {
return nil, err
}
return q.WithTx(tx), nil
}
{{- end }}
{{end}}
{{end}}