-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbinary_operator.go
More file actions
56 lines (48 loc) · 1009 Bytes
/
binary_operator.go
File metadata and controls
56 lines (48 loc) · 1009 Bytes
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
package repository
import (
"github.com/globalsign/mgo/bson"
)
type binaryOperatorType int
const (
// Comparison Operators
BinaryOperatorTypeEq = iota
BinaryOperatorTypeGT
BinaryOperatorTypeGTE
BinaryOperatorTypeIN
BinaryOperatorTypeLT
BinaryOperatorTypeLTE
BinaryOperatorTypeNE
BinaryOperatorTypeNIN
// Element Operators
BinaryOperatorTypeExists
// Evaluation Operators
BinaryOperatorTypeRegex
)
type BinaryOperator interface {
GetCondition() (bson.DocElem, error)
}
type BinaryOperatorImpl struct {
OpField *string
FieldName string
Type binaryOperatorType
Value interface{}
}
func (o *BinaryOperatorImpl) GetCondition() (bson.DocElem, error) {
switch o.Type {
case BinaryOperatorTypeEq:
return bson.DocElem{Name: o.FieldName, Value: o.Value}, nil
}
if o.FieldName == "" {
return bson.DocElem{
Name: *o.OpField,
Value: o.Value,
}, nil
} else {
return bson.DocElem{
Name: o.FieldName,
Value: bson.M{
*o.OpField: o.Value,
},
}, nil
}
}