-
Notifications
You must be signed in to change notification settings - Fork 2
/
sql.go
64 lines (55 loc) · 1.9 KB
/
sql.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
package coresql
import (
"context"
"database/sql"
"database/sql/driver"
"time"
)
// Pinger defines a common set of methods for pinging an SQL database.
type Pinger interface {
PingContext(ctx context.Context) error
Ping() error
}
// Connector defines a common set of methods for dealing with the connection to an SQL database.
type Connector interface {
Driver() driver.Driver
SetMaxIdleConns(n int)
SetMaxOpenConns(n int)
SetConnMaxLifetime(d time.Duration)
Conn(ctx context.Context) (*sql.Conn, error)
Stats() sql.DBStats
}
// Preparer defines a common set of methods for preparing statements in an SQL database.
type Preparer interface {
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
Prepare(query string) (*sql.Stmt, error)
}
// Transactor defines a common set of methods for working with database transactions.
type Transactor interface {
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
Begin() (*sql.Tx, error)
}
// Executor defines a common set of methods for executing stored procedures, statements or queries.
type Executor interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec(query string, args ...interface{}) (sql.Result, error)
}
// Querier defines a common set of methods for querying an SQL database.
type Querier interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryRow(query string, args ...interface{}) *sql.Row
}
// Agent defines a common set of methods for interacting with the data in an SQL database.
type Agent interface {
Preparer
Transactor
Executor
Querier
}
// Operator defines a common set of methods for operating a connection with an SQL database.
type Operator interface {
Pinger
Connector
}