-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathListMap.go
48 lines (46 loc) · 1.23 KB
/
ListMap.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
package gpa
import "github.com/cihub/seelog"
func (dao *Gpa) ListMapStringString(sql string, param ...interface{}) ([]map[string]string, error) {
defer func() {
if err := recover(); err != nil {
seelog.Error("Query fail.\n\t", sql , param, "\n", err)
}
}()
rows, err := dao.Conn.Query(sql, param...)
defer rows.Close()
if err == nil {
if cols, ec := rows.Columns(); ec == nil {
result := make([]map[string]string, 0)
for rows.Next() {
result = append(result, RowToMap(rows, cols))
}
return result, nil
}
} else {
seelog.Flush()
seelog.Error("ListMapStringString Error:", sql, err)
}
return nil, nil
}
func (dao *Gpa) ListMapStringInterface(sql string, param ...interface{}) ([]map[string]interface{}, error) {
defer func() {
if err := recover(); err != nil {
seelog.Error("Query fail.\n\t", sql , param, "\n", err)
}
}()
rows, err := dao.Conn.Query(sql, param...)
defer rows.Close()
if err == nil {
if cols, ec := rows.Columns(); ec == nil {
result := make([]map[string]interface{}, 0)
for rows.Next() {
result = append(result, rowToInterface(rows, cols))
}
return result, nil
}
} else {
seelog.Flush()
seelog.Error("ListMapStringString Error:", sql, err)
}
return nil, nil
}