forked from go-rel/rel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_query.go
41 lines (34 loc) · 942 Bytes
/
group_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
package rel
// GroupQuery defines group clause of the query.
type GroupQuery struct {
Fields []string
Filter FilterQuery
}
// Build query.
func (gq GroupQuery) Build(query *Query) {
query.GroupQuery = gq
}
// Having appends filter for group query with and operand.
func (gq GroupQuery) Having(filters ...FilterQuery) GroupQuery {
gq.Filter = gq.Filter.And(filters...)
return gq
}
// OrHaving appends filter for group query with or operand.
func (gq GroupQuery) OrHaving(filters ...FilterQuery) GroupQuery {
gq.Filter = gq.Filter.Or(And(filters...))
return gq
}
// Where is alias for having.
func (gq GroupQuery) Where(filters ...FilterQuery) GroupQuery {
return gq.Having(filters...)
}
// OrWhere is alias for OrHaving.
func (gq GroupQuery) OrWhere(filters ...FilterQuery) GroupQuery {
return gq.OrHaving(filters...)
}
// NewGroup query.
func NewGroup(fields ...string) GroupQuery {
return GroupQuery{
Fields: fields,
}
}