forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_counter.go
67 lines (48 loc) · 1.28 KB
/
query_counter.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
package metric
import (
"database/sql"
"github.com/Masterminds/squirrel"
"github.com/concourse/atc/db"
)
func CountQueries(conn db.Conn) db.Conn {
return &countingConn{
Conn: conn,
}
}
type countingConn struct {
db.Conn
}
func (e *countingConn) Query(query string, args ...interface{}) (*sql.Rows, error) {
DatabaseQueries.Inc()
return e.Conn.Query(query, args...)
}
func (e *countingConn) QueryRow(query string, args ...interface{}) squirrel.RowScanner {
DatabaseQueries.Inc()
return e.Conn.QueryRow(query, args...)
}
func (e *countingConn) Exec(query string, args ...interface{}) (sql.Result, error) {
DatabaseQueries.Inc()
return e.Conn.Exec(query, args...)
}
func (e *countingConn) Begin() (db.Tx, error) {
tx, err := e.Conn.Begin()
if err != nil {
return tx, err
}
return &countingTx{Tx: tx}, nil
}
type countingTx struct {
db.Tx
}
func (e *countingTx) Query(query string, args ...interface{}) (*sql.Rows, error) {
DatabaseQueries.Inc()
return e.Tx.Query(query, args...)
}
func (e *countingTx) QueryRow(query string, args ...interface{}) squirrel.RowScanner {
DatabaseQueries.Inc()
return e.Tx.QueryRow(query, args...)
}
func (e *countingTx) Exec(query string, args ...interface{}) (sql.Result, error) {
DatabaseQueries.Inc()
return e.Tx.Exec(query, args...)
}