-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx.go
70 lines (54 loc) · 1.33 KB
/
tx.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package pgsqlxx
import (
"github.com/jackc/pgx"
"github.com/jmoiron/sqlx/reflectx"
)
// Allow easy access to pgsqlxx Tx without needing to use the rest of the library
func TxFromTx(tx *pgx.Tx, mapper *reflectx.Mapper) *Tx {
return &Tx{Tx: tx, unsafe: false, Mapper: mapper}
}
// Allow easy access to pgsqlxx Tx without needing to use the rest of the library
func TxFromTxUnsafe(tx *pgx.Tx, mapper *reflectx.Mapper) *Tx {
return &Tx{Tx: tx, unsafe: true, Mapper: mapper}
}
type Tx struct {
*pgx.Tx
unsafe bool
Mapper *reflectx.Mapper
}
func (t *Tx) Queryx(query string, args ...interface{}) (*Rows, error) {
rows, err := t.Tx.Query(query, args...)
if err != nil {
return nil, err
}
r := RowsFromRows(rows, t.Mapper)
r.unsafe = t.unsafe
return r, nil
}
func (t *Tx) QueryRowx(query string, args ...interface{}) *Row {
rows, err := t.Queryx(query, args...)
r := RowFromRowsx(rows, t.Mapper)
r.unsafe = t.unsafe
r.err = err
return r
}
func (t *Tx) Rebind(query string) string {
return Rebind(query)
}
func (t *Tx) Execx(sql string, args ...interface{}) (*Result, error) {
r, err := t.Exec(sql, args...)
if err != nil {
return nil, err
}
return ResultFromCommandTag(r), nil
}
func (t *Tx) Unsafe() *Tx {
t.unsafe = true
return t
}
func (t *Tx) IsTx() bool {
return true
}
func (t *Tx) DriverName() string {
return "pgx"
}