-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquery.go
78 lines (67 loc) · 1.51 KB
/
query.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
package gosql
const (
QueryKeyAnd string = "%and" // AND 与
QueryKeyOr = "%or" // OR 或
)
const (
QueryKeyEq string = "%eq" // 等于
QueryKeyNe = "%ne" // 不等于
QueryKeyLt = "%lt" // 小于
QueryKeyLte = "%lte" // 小于等于
QueryKeyGt = "%gt" // 大于
QueryKeyGte = "%gte" // 大于等于
QueryKeyLike = "%like" // 模糊搜索
QueryKeyIn = "%in" // 在...之中
QueryKeyBetween = "%bt" // 在...之间
QueryKeyNotBetween = "%nbt" // 不在...之间
)
func IsQueryKey(str string) bool {
switch str {
case QueryKeyAnd, QueryKeyOr:
return true
}
return IsQueryAnonymousKey(str)
}
func IsQueryAnonymousKey(str string) bool {
switch str {
case QueryKeyEq, QueryKeyNe:
return true
case QueryKeyLt, QueryKeyLte:
return true
case QueryKeyGt, QueryKeyGte:
return true
case QueryKeyLike:
return true
case QueryKeyIn:
return true
case QueryKeyBetween, QueryKeyNotBetween:
return true
}
return false
}
type IQuery interface {
IsAnonymous() bool
}
type QueryRoot struct {
Values []IQuery
}
func (q *QueryRoot) IsAnonymous() bool {
return false
}
type QueryElem struct {
anonymous bool
RelKey string
Key string
Values []IQuery
}
func (q *QueryElem) IsAnonymous() bool {
return q.anonymous
}
type QueryValue struct {
Key string
Field string
Value interface{}
}
func (q *QueryValue) IsAnonymous() bool {
return false
}