-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_builder.go
48 lines (39 loc) · 948 Bytes
/
sql_builder.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 rest
type OrderPair struct {
key string
value string
}
type WherePair struct {
Query string
Args []interface{}
}
func (this *WherePair) And(where *WherePair) *WherePair {
if this.Query == "" {
return where
} else {
return &WherePair{Query: this.Query + " AND " + where.Query, Args: append(this.Args, where.Args...)}
}
}
func (this *WherePair) Or(where *WherePair) *WherePair {
if this.Query == "" {
return where
} else {
return &WherePair{Query: this.Query + " OR " + where.Query, Args: append(this.Args, where.Args...)}
}
}
//根据一个sortMap,获取到order字符串
func (this *BaseDao) GetSortString(sortArray []OrderPair) string {
if sortArray == nil || len(sortArray) == 0 {
return ""
}
str := ""
for _, pair := range sortArray {
if pair.value == "DESC" || pair.value == "ASC" {
if str != "" {
str = str + ","
}
str = str + " " + pair.key + " " + pair.value
}
}
return str
}