-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.go
76 lines (57 loc) · 1.14 KB
/
db.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
73
74
75
76
package sql
import (
"context"
"database/sql"
)
type (
Result = sql.Result
NullInt64 = sql.NullInt64
NullString = sql.NullString
NullBool = sql.NullBool
)
var (
ErrConnDone = sql.ErrConnDone
ErrNoRows = sql.ErrNoRows
ErrTxDone = sql.ErrTxDone
)
type Option interface {
IsSQLOption()
}
type Scanner interface {
Scan(...interface{}) error
}
type Queryer interface {
Exec(context.Context, string, ...interface{}) (Result, error)
QueryRow(context.Context, string, ...interface{}) Scanner
Query(context.Context, string, ...interface{}) (Cursor, error)
}
type DB interface {
Queryer
BeginTx(context.Context, TxOptions) (Tx, error)
Driver() string
}
type TxOptions struct {
Isolation IsolationLevel
}
type Returning struct {
Field string
}
func (Returning) IsSQLOption() {}
type Consistency uint8
func (Consistency) IsSQLOption() {}
const (
EventuallyConsistent Consistency = iota
StronglyConsistent
)
func StripOptions(vs []interface{}) []interface{} {
var res []interface{}
for _, v := range vs {
if _, ok := v.(Option); !ok {
res = append(res, v)
}
}
return res
}
type MiddlewareFactory interface {
Wrap(DB) DB
}