-
Notifications
You must be signed in to change notification settings - Fork 57
/
condition.go
83 lines (68 loc) · 1.67 KB
/
condition.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
package crud
import "strconv"
type EnumOP string
const (
EQ EnumOP = "eq"
NE EnumOP = "ne"
GT EnumOP = "gt"
GE EnumOP = "ge"
LT EnumOP = "lt"
LE EnumOP = "le"
Limit EnumOP = "limit"
)
type Condition struct {
conditions map[string]map[EnumOP]string
}
func NewCondition() *Condition {
return &Condition{conditions: make(map[string]map[EnumOP]string)}
}
func (c *Condition) EQ(key string, value string) {
newMap := make(map[EnumOP]string)
newMap[EQ] = value
c.conditions[key] = newMap
}
func (c *Condition) NE(key string, value string) {
newMap := make(map[EnumOP]string)
newMap[NE] = value
c.conditions[key] = newMap
}
func (c *Condition) GT(key string, value string) {
newMap := make(map[EnumOP]string)
newMap[GT] = value
c.conditions[key] = newMap
}
func (c *Condition) GE(key string, value string) {
newMap := make(map[EnumOP]string)
newMap[GE] = value
c.conditions[key] = newMap
}
func (c *Condition) LT(key string, value string) {
newMap := make(map[EnumOP]string)
newMap[LT] = value
c.conditions[key] = newMap
}
func (c *Condition) LE(key string, value string) {
newMap := make(map[EnumOP]string)
newMap[LE] = value
c.conditions[key] = newMap
}
func (c *Condition) Limit(count int) {
c.limit(0, count)
}
func (c *Condition) limit(offset int, count int) {
newMap := make(map[EnumOP]string)
if offset < 0 {
offset = 0
}
if count < 0 {
count = 0
}
newMap[Limit] = strconv.Itoa(offset) + "," + strconv.Itoa(count)
c.conditions["limit"] = newMap
}
func (c *Condition) GetConditions() map[string]map[EnumOP]string {
return c.conditions
}
func (c *Condition) SetConditions(newMap map[string]map[EnumOP]string) {
c.conditions = newMap
}