-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
query.go
59 lines (54 loc) · 1.25 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
package distil
import "fmt"
// Query ...
type Query struct {
Filters []Filter
}
// Filter represents fields needed to distil a dataset.
type Filter struct {
Field string `json:"field"`
Operator Operator `json:"operator"`
Value interface{} `json:"value"`
}
// Operator represents a filter operator that will be used to distil a dataset.
type Operator struct {
Code string `json:"code"`
Type string `json:"type"`
}
// distiller returns a distiller instance based on the filter operator.
func (f *Filter) distiller() (distiller, error) {
switch f.Operator.Code {
case "eq":
return &eq{}, nil
case "not_eq":
return ¬Eq{}, nil
case "starts_with":
return &startsWith{}, nil
case "matches":
return &matches{}, nil
case "does_not_match":
return ¬Matches{}, nil
case "is_null":
return &isNull{}, nil
case "not_null":
return ¬Null{}, nil
case "lt":
return <{}, nil
case "gt":
return >{}, nil
case "lteq":
return <eq{}, nil
case "gteq":
return >eq{}, nil
case "contains":
return &contains{}, nil
case "does_not_contain":
return ¬Contains{}, nil
case "is_true":
return &isTrue{}, nil
case "is_false":
return &isFalse{}, nil
default:
return nil, fmt.Errorf("Unknown operator ID: %v", f.Operator)
}
}