-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn.go
49 lines (40 loc) · 943 Bytes
/
conn.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
package gosqlcache
import (
"database/sql/driver"
"time"
)
import . "./interfaces"
// Implements driver.Conn
type cacheConn struct {
driver.Conn
driver.Queryer
driver.Execer
cache SqlCacher
pendingQueries []stmt
cacheMap map[string]time.Duration
log Logger
}
func (c *cacheConn) Prepare(query string) (driver.Stmt, error) {
s, err := c.Conn.Prepare(query)
return &stmt{query, c, s}, err
}
// make stmt then execute statement
func (c *cacheConn) Query(query string, args []driver.Value) (r driver.Rows, err error) {
s, err := c.Prepare(query)
if err != nil {
return
}
return s.Query(args)
}
func (c *cacheConn) RegisterQuery(query string, d time.Duration) {
c.cacheMap[query] = d
}
func (c *cacheConn) SetLogger(l Logger) {
c.log = l
}
func (c *cacheConn) SetCacher(cache Cacher) {
c.cache = &SqlCache{cache, c.log}
}
func (c *cacheConn) SetSqlCacher(cache SqlCacher) {
c.cache = cache
}