-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap_conn.go
More file actions
51 lines (42 loc) · 1.04 KB
/
wrap_conn.go
File metadata and controls
51 lines (42 loc) · 1.04 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
package dbx
import (
"context"
"database/sql"
)
// WrapConn ...
func WrapConn(conn *sql.Conn) Conn {
return &wrapConn{conn: conn}
}
type wrapConn struct {
conn *sql.Conn
}
func (c *wrapConn) Ping(ctx context.Context) error {
return c.conn.PingContext(ctx)
}
func (c *wrapConn) BeginTx(ctx context.Context, opts TxOptions) (Tx, error) {
tx, err := c.conn.BeginTx(ctx, convTxOptions(opts))
if err != nil {
return nil, err
}
return WrapTx(tx), nil
}
func (c *wrapConn) Exec(ctx context.Context, query string, args ...any) (Result, error) {
res, err := c.conn.ExecContext(ctx, query, args...)
if err != nil {
return nil, err
}
return wrapRes(res), nil
}
func (c *wrapConn) Query(ctx context.Context, query string, args ...any) (Rows, error) {
rows, err := c.conn.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
return rows, err
}
func (c *wrapConn) QueryRow(ctx context.Context, query string, args ...any) Row {
return c.conn.QueryRowContext(ctx, query, args...)
}
func (c *wrapConn) Close() error {
return c.Close()
}