forked from jmoiron/modl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle.go
51 lines (42 loc) · 1.42 KB
/
handle.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 modl
import (
"database/sql"
"github.com/jmoiron/sqlx"
)
// a cursor is either an sqlx.Db or an sqlx.Tx
type handle interface {
Select(dest interface{}, query string, args ...interface{}) error
Get(dest interface{}, query string, args ...interface{}) error
Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
QueryRowx(query string, args ...interface{}) *sqlx.Row
Exec(query string, args ...interface{}) (sql.Result, error)
/*
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
*/
}
// an implmentation of handle which traces using dbmap
type tracingHandle struct {
d *DbMap
h handle
}
func (t *tracingHandle) Select(dest interface{}, query string, args ...interface{}) error {
t.d.trace(query, args...)
return t.h.Select(dest, query, args...)
}
func (t *tracingHandle) Get(dest interface{}, query string, args ...interface{}) error {
t.d.trace(query, args...)
return t.h.Get(dest, query, args...)
}
func (t *tracingHandle) Queryx(query string, args ...interface{}) (*sqlx.Rows, error) {
t.d.trace(query, args...)
return t.h.Queryx(query, args...)
}
func (t *tracingHandle) QueryRowx(query string, args ...interface{}) *sqlx.Row {
t.d.trace(query, args...)
return t.h.QueryRowx(query, args...)
}
func (t *tracingHandle) Exec(query string, args ...interface{}) (sql.Result, error) {
t.d.trace(query, args...)
return t.h.Exec(query, args...)
}