-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver_go1.8.go
81 lines (74 loc) · 1.89 KB
/
driver_go1.8.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
77
78
79
80
81
//go:build !go1.9
// +build !go1.9
package dbwrap
import (
"context"
"database/sql/driver"
"errors"
)
// Dummy error for setSpanStatus (does exist as sql.ErrConnDone in 1.9+)
var errConnDone = errors.New("database/sql: connection is already closed")
// wDriver implements driver.Driver
type wDriver struct {
parent driver.Driver
options Options
}
func wrapDriver(d driver.Driver, o Options) driver.Driver {
return wDriver{parent: d, options: o}
}
func wrapConn(c driver.Conn, options Options) driver.Conn {
return &wConn{parent: c, options: options}
}
func wrapStmt(ctx context.Context, stmt driver.Stmt, query string, options Options) driver.Stmt {
s := wStmt{ctx: ctx, parent: stmt, query: query, options: options}
_, hasExeCtx := stmt.(driver.StmtExecContext)
_, hasQryCtx := stmt.(driver.StmtQueryContext)
c, hasColCnv := stmt.(driver.ColumnConverter)
switch {
case !hasExeCtx && !hasQryCtx && !hasColCnv:
return struct {
driver.Stmt
}{s}
case !hasExeCtx && hasQryCtx && !hasColCnv:
return struct {
driver.Stmt
driver.StmtQueryContext
}{s, s}
case hasExeCtx && !hasQryCtx && !hasColCnv:
return struct {
driver.Stmt
driver.StmtExecContext
}{s, s}
case hasExeCtx && hasQryCtx && !hasColCnv:
return struct {
driver.Stmt
driver.StmtExecContext
driver.StmtQueryContext
}{s, s, s}
case !hasExeCtx && !hasQryCtx && hasColCnv:
return struct {
driver.Stmt
driver.ColumnConverter
}{s, c}
case !hasExeCtx && hasQryCtx && hasColCnv:
return struct {
driver.Stmt
driver.StmtQueryContext
driver.ColumnConverter
}{s, s, c}
case hasExeCtx && !hasQryCtx && hasColCnv:
return struct {
driver.Stmt
driver.StmtExecContext
driver.ColumnConverter
}{s, s, c}
case hasExeCtx && hasQryCtx && hasColCnv:
return struct {
driver.Stmt
driver.StmtExecContext
driver.StmtQueryContext
driver.ColumnConverter
}{s, s, s, c}
}
panic("unreachable")
}