-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilter_query.go
60 lines (46 loc) · 1.34 KB
/
filter_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
package gobs
type filterQuery struct {
filters []filter
settings *settings
}
type filter struct {
field string
value interface{}
}
type getFilter interface{
getFilter() map[string]interface{}
}
func (fq filterQuery) Find(dataObject interface{}) error {
contentTypeName, err := getContentTypeName(dataObject)
if err != nil {
return err
}
return fq.readMany(contentTypeName, dataObject)
}
func (fq filterQuery) RemoveMany(dataObject interface{}) error {
contentTypeName, err := getContentTypeName(dataObject)
if err != nil {
return err
}
return fq.removeMany(contentTypeName, dataObject)
}
func (fq filterQuery) Where(field string, value interface{}) filterQuery {
filter := filter{field: field, value: value}
fq.filters = append(fq.filters, filter)
return fq
}
func (fq filterQuery) WhereNot(field string, value interface{}) filterQuery {
operator := "$ne"
notFilter := make(map[string]interface{})
notFilter[operator] = value
notEqualFilter := filter{field: field, value: notFilter}
fq.filters = append(fq.filters, notEqualFilter)
return fq
}
func (fq filterQuery) Count(object interface{}) (count int, err error) {
contentTypeName, err := getContentTypeName(object)
if err != nil {
return 0, err
}
return fq.count(contentTypeName)
}