forked from jmoiron/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlx_conn.go
More file actions
103 lines (86 loc) · 2.49 KB
/
sqlx_conn.go
File metadata and controls
103 lines (86 loc) · 2.49 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package sqlx
import (
"context"
"database/sql"
)
// Conn
type Conn struct {
*sql.Conn
db *DB
}
// Conn
func (db *DB) Conn(ctx context.Context) (*Conn, error) {
conn, err := db.DB.Conn(ctx)
if err != nil {
return nil, err
}
return &Conn{
Conn: conn,
db: db,
}, nil
}
// Close
func (c *Conn) Close() {
c.Conn.Close()
}
// DriverName
func (c *Conn) DriverName() string {
return c.db.DriverName()
}
// Rebind
func (c *Conn) Rebind(query string) string {
return c.db.Rebind(query)
}
// BindNamed
func (c *Conn) BindNamed(query string, arg interface{}) (string, []interface{}, error) {
return c.db.BindNamed(query, arg)
}
// BeginTxx
func (c *Conn) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
tx, err := c.Conn.BeginTx(ctx, opts)
if err != nil {
return nil, err
}
return &Tx{Tx: tx, driverName: c.db.driverName, unsafe: c.db.unsafe, Mapper: c.db.Mapper}, err
}
// Beginx
func (c *Conn) Beginx() (*Tx, error) {
return c.BeginTxx(context.Background(), nil)
}
// PrepareNamedContext
func (c *Conn) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error) {
return prepareNamedContext(ctx, c, query)
}
// NamedQueryContext
func (c *Conn) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*Rows, error) {
return NamedQueryContext(ctx, c, query, arg)
}
// NamedExecContext
func (c *Conn) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
return NamedExecContext(ctx, c, query, arg)
}
// PreparexContext
func (c *Conn) PreparexContext(ctx context.Context, query string) (*Stmt, error) {
return PreparexContext(ctx, c, query)
}
// SelectContext
func (c *Conn) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return SelectContext(ctx, c, dest, query, args...)
}
// GetContext
func (c *Conn) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return GetContext(ctx, c, dest, query, args...)
}
// QueryxContext
func (c *Conn) QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
r, err := c.Conn.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
return &Rows{Rows: r, unsafe: c.db.unsafe, Mapper: c.db.Mapper}, err
}
// QueryRowxContext
func (c *Conn) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row {
rows, err := c.Conn.QueryContext(ctx, query, args...)
return &Row{rows: rows, err: err, unsafe: c.db.unsafe, Mapper: c.db.Mapper}
}