-
Notifications
You must be signed in to change notification settings - Fork 0
/
setter.go
executable file
·99 lines (85 loc) · 1.94 KB
/
setter.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package lql
import (
"database/sql"
)
func (m *DBPool) SetDebuger(debuger func(...interface{})) {
m.d = debuger
m.debug("dbpool set debuger success")
}
func (m *DBPool) debug(p ...interface{}) {
m.d(p...)
}
func (m *DBPool) debugSql(p ...interface{}) {
if m.sqlDebug {
m.debug(p...)
}
}
func (m *DBPool) Query(query string, args ...interface{}) []map[string]string {
m.debugSql("Query sql :(", query, ")", args)
rows, err := m.currDB.Query(query, args...)
if err != nil {
return nil
}
defer rows.Close()
res := make([]map[string]string, 0)
for rows.Next() {
res = append(res, parseRow(rows))
}
return res
}
func (m *DBPool) QueryRows(query string, args ...interface{}) ([]map[string]string, error) {
m.debugSql("Query sql :(", query, ")", args)
rows, err := m.currDB.Query(query, args...)
if err != nil {
return nil, err
}
defer rows.Close()
res := make([]map[string]string, 0)
for rows.Next() {
res = append(res, parseRow(rows))
}
return res, nil
}
func (m *DBPool) QueryRow(query string, args ...interface{}) (map[string]string, error) {
m.debugSql("Query Row sql :(", query, ")", args)
rows, err := m.currDB.Query(query, args...)
if err != nil {
return nil, err
}
defer rows.Close()
if rows.Next() {
return parseRow(rows), nil
}
return nil, err
}
func (m *DBPool) Exec(sql string, args ...interface{}) (sql.Result, error) {
m.debugSql("Exec sql :(", sql, ")", args)
res, err := m.currDB.Exec(sql, args...)
if err != nil {
}
return res, err
}
func (m *DBPool) Prepare(query string) (*sql.Stmt, error) {
return m.currDB.Prepare(query)
}
func (m *DBPool) GetDb() *sql.DB {
return m.currDB
}
func (m *DBPool) Close() {
m.currDB.Close()
}
func (m *DBPool) Ping() error {
return m.currDB.Ping()
}
func (m *DBPool) IsConn() bool {
return m.isConn
}
func (m *DBPool) Err() error {
return m.err
}
func (m *DBPool) Begin() (*sql.Tx, error) {
return m.currDB.Begin()
}
func (m *DBPool) OpenSqlDebugger() {
m.sqlDebug = true
}