Repository navigation
Expand file tree
/
Copy pathdb.go
More file actions
86 lines (65 loc) · 1.34 KB
/
Copy pathdb.go
File metadata and controls
86 lines (65 loc) · 1.34 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
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(...any) error
}
type Queryer interface {
Exec(context.Context, string, ...any) (Result, error)
QueryRow(context.Context, string, ...any) Scanner
Query(context.Context, string, ...any) (Cursor, error)
}
type DB interface {
Queryer
BeginTx(context.Context, TxOptions) (Tx, error)
Driver() string
}
// DriverOf returns the driver of q, the DBs and the transactions they
// begin expose it. It returns an empty string when q does not.
func DriverOf(q Queryer) string {
if d, ok := q.(interface{ Driver() string }); ok {
return d.Driver()
}
return ""
}
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 []any) []any {
var res []any
for _, v := range vs {
if _, ok := v.(Option); !ok {
res = append(res, v)
}
}
return res
}
type MiddlewareFactory interface {
Wrap(DB) DB
}