-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathdbCode.tmpl
More file actions
43 lines (38 loc) · 962 Bytes
/
dbCode.tmpl
File metadata and controls
43 lines (38 loc) · 962 Bytes
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
{{define "dbCodeTemplatePgx"}}
type DBTX interface {
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,
}
}
{{end}}
{{if .ExposeDbConnection}}
func (q *Queries) Conn() DBTX {
return q.db
}
{{end}}
{{end}}