-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgresr.go
72 lines (56 loc) · 1.58 KB
/
postgresr.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
71
72
package postgresr
import (
"context"
"github.com/jackc/pgconn"
"github.com/jackc/pgx/v4"
)
/******************************************************************************
* Structs
*****************************************************************************/
type PgxConn struct {
conn *pgx.Conn
}
/******************************************************************************
* Methods
*****************************************************************************/
func Connect(ctx context.Context, connString string) (Conn, error) {
var (
err error
conn *pgx.Conn
result *PgxConn
)
if conn, err = pgx.Connect(ctx, connString); err != nil {
return result, err
}
return &PgxConn{
conn: conn,
}, nil
}
func ConnectConfig(ctx context.Context, connConfig *pgx.ConnConfig) (Conn, error) {
var (
err error
conn *pgx.Conn
result *PgxConn
)
if conn, err = pgx.ConnectConfig(ctx, connConfig); err != nil {
return result, err
}
return &PgxConn{
conn: conn,
}, nil
}
func (c *PgxConn) Close(ctx context.Context) error {
return c.conn.Close(ctx)
}
func (c *PgxConn) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error) {
return c.conn.Exec(ctx, sql, arguments...)
}
func (c *PgxConn) Ping(ctx context.Context) error {
return c.conn.Ping(ctx)
}
func (c *PgxConn) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error) {
return c.conn.Query(ctx, sql, args...)
}
func (c *PgxConn) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row {
return c.conn.QueryRow(ctx, sql, args...)
}