File tree 2 files changed +14
-3
lines changed
2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,9 @@ func (i *importer) dbImports() fileImports {
142
142
pkg = append (pkg , ImportSpec {Path : "github.com/jackc/pgx/v5" })
143
143
if len (i .CompositeTypes ) > 0 {
144
144
pkg = append (pkg , ImportSpec {Path : "github.com/jackc/pgx/v5/pgtype" })
145
+ if ! i .Options .EmitMethodsWithDbArgument {
146
+ pkg = append (pkg , ImportSpec {Path : "fmt" })
147
+ }
145
148
}
146
149
default :
147
150
std = append (std , ImportSpec {Path : "database/sql" })
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ type DBTX interface {
10
10
{{- if .UsesBatch }}
11
11
SendBatch(context.Context, *pgx.Batch) pgx.BatchResults
12
12
{{- end }}
13
+ }
14
+
15
+ type DB interface {
16
+ DBTX
13
17
{{- if gt (len .CompositeTypes) 0 }}
14
18
LoadTypes(ctx context.Context, typeNames []string) ([]*pgtype.Type, error)
15
19
TypeMap() *pgtype.Map
@@ -20,7 +24,7 @@ type DBTX interface {
20
24
func New() *Queries {
21
25
return &Queries{}
22
26
{{- else -}}
23
- func New(db DBTX ) *Queries {
27
+ func New(db DB ) *Queries {
24
28
return &Queries{db: db}
25
29
{{- end}}
26
30
}
@@ -34,13 +38,17 @@ type Queries struct {
34
38
{{if gt (len .CompositeTypes) 0}}
35
39
{{if not .EmitMethodsWithDBArgument}}
36
40
func (q *Queries) RegisterTypes(ctx context.Context) error {
37
- db := q.db
41
+ db, ok := q.db.(DB)
42
+ if !ok {
43
+ return fmt.Errorf("cannot register types with a transaction object")
44
+ }
38
45
{{else}}
39
- func (q *Queries) RegisterTypes(ctx context.Context, db *Queries ) error {
46
+ func (q *Queries) RegisterTypes(ctx context.Context, db DB ) error {
40
47
{{end}}
41
48
typeNames := []string{
42
49
{{- range .CompositeTypes}}
43
50
"{{.SQLName}}",
51
+ "_{{.SQLName}}",
44
52
{{- end}}
45
53
}
46
54
dataTypes, err := db.LoadTypes(ctx, typeNames)
You can’t perform that action at this time.
0 commit comments