-
Notifications
You must be signed in to change notification settings - Fork 3
/
query.go
94 lines (79 loc) · 1.86 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package goar
type EnumRelationalOperators int
const (
_ EnumRelationalOperators = iota
EQ // equal
NE // not equal
LT // less than
LTE // less than or equal
GT // greater than
GTE // greater than or equal
IN
)
type EnumLogicalOperators int
const (
_ EnumLogicalOperators = iota
OR
AND
NOT
)
type EnumSortOrders int
const (
_ EnumSortOrders = iota
ASC
DESC
)
type EnumAggregations int
const (
_ EnumAggregations = iota
SUM
GROUP
)
type Querier interface {
Query() *Query
SetQuery(*Query)
Pluck(...interface{}) *ActiveRecord
Where(QueryCondition) *ActiveRecord
Order(OrderBy) *ActiveRecord
Sum(fields ...interface{}) *ActiveRecord
Distinct() *ActiveRecord
//Or(QueryCondition) *ActiveRecord
Run(results interface{}) error
}
type Query struct {
//db *DB
//OrConditions []QueryCondition
//NotConditions []QueryCondition
Plucks []interface{}
WhereConditions []QueryCondition
OrderBys []OrderBy
Joins string
Offset string
Limit string
Aggregations map[EnumAggregations][]interface{}
Distinct bool
err error
}
type QueryCondition struct {
LogicalOperator EnumLogicalOperators
Key string
RelationalOperator EnumRelationalOperators
Value interface{}
}
type OrderBy struct {
Key string
SortOrder EnumSortOrders
}
func NewQuery() *Query {
return &Query{
Aggregations: make(map[EnumAggregations][]interface{}),
Distinct: false}
}
//func (q *Query) Where(where WhereCondition) *Query {
//q.WhereConditions = append(q.WhereConditions, where)
//return q
//}
//func (q *Query) Run(results interface{}) error {
//model := q.Model
//return model.(Persister).DbSearch(results)
//}