-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
51 lines (42 loc) · 866 Bytes
/
driver.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
package gosqlcache
import (
"database/sql/driver"
"io/ioutil"
"log"
"time"
)
import . "./interfaces"
func NewSqlCacheDriver(d driver.Driver, c SqlCacher, l Logger) *SqlCacheDriver {
if l == nil {
l = log.New(ioutil.Discard, "", 0)
}
return &SqlCacheDriver{
Driver: d,
SqlCacher: c,
Logger: l,
cacheConn: &cacheConn{
cache: c,
cacheMap: map[string]time.Duration{},
log: l,
},
}
}
type SqlCacheDriver struct {
driver.Driver
SqlCacher
Logger
*cacheConn
}
func (d *SqlCacheDriver) Open(name string) (driver.Conn, error) {
return Open(d, name)
}
func Open(d *SqlCacheDriver, name string) (*cacheConn, error) {
cn, err := d.Driver.Open(name)
if err != nil {
return nil, err
}
d.cacheConn.Conn = cn
d.cacheConn.Queryer = cn.(driver.Queryer)
d.cacheConn.Execer = cn.(driver.Execer)
return d.cacheConn, nil
}