-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwrap.go
40 lines (30 loc) · 887 Bytes
/
wrap.go
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
package sqlc
import (
"context"
"database/sql"
)
var _ DBTX = (*wrappedDB)(nil)
func Wrap(db DBTX) DBTX {
return &wrappedDB{db}
}
type wrappedDB struct {
DBTX
}
func (w wrappedDB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
if b, ok := BuilderFrom(ctx); ok {
query, args = b.Build(query, args...)
}
return w.DBTX.ExecContext(ctx, query, args...)
}
func (w wrappedDB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
if b, ok := BuilderFrom(ctx); ok {
query, args = b.Build(query, args...)
}
return w.DBTX.QueryContext(ctx, query, args...)
}
func (w wrappedDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
if b, ok := BuilderFrom(ctx); ok {
query, args = b.Build(query, args...)
}
return w.DBTX.QueryRowContext(ctx, query, args...)
}