-
Notifications
You must be signed in to change notification settings - Fork 0
/
q_conditions.go
48 lines (40 loc) · 1 KB
/
q_conditions.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
package dal
import (
"fmt"
"reflect"
)
type Condition interface {
fmt.Stringer
}
// Comparison defines a contact for a comparison
type Comparison struct {
Operator Operator
Left Expression
Right Expression
}
func (v Comparison) Equal(b Comparison) bool {
return v.Operator == b.Operator && reflect.DeepEqual(v.Left, b.Left) && reflect.DeepEqual(v.Right, b.Right)
}
// IsGroupOperator says if an operator is a group operator
func IsGroupOperator(o Operator) bool {
return o == In
}
// String returns string representation of a comparison
func (v Comparison) String() string {
o := v.Operator
switch o {
case Equal:
o = "="
case "":
o = "{NO_OPERATOR}"
}
return fmt.Sprintf("%v %v %v", v.Left, o, v.Right)
}
// NewComparison creates new Comparison
func NewComparison(left Expression, o Operator, right Expression) Comparison {
return Comparison{Operator: o, Left: left, Right: right}
}
// String creates a new Constant expression
func String(v string) Expression {
return Constant{Value: v}
}