github.com/aacfactory/fns-contrib/databases/sql@v1.2.84/dac/conditions/conditions.go (about) 1 package conditions 2 3 func New(predicate Predicate) Condition { 4 return Condition{ 5 Operation: "", 6 Left: predicate, 7 Right: nil, 8 Group: false, 9 } 10 } 11 12 // Condition 13 // tree 14 type Condition struct { 15 Operation Operation 16 Left Node 17 Right Node 18 Group bool 19 } 20 21 func (cond Condition) Exist() bool { 22 return cond.Left != nil 23 } 24 25 func (cond Condition) join(op Operation, right Node) (n Condition) { 26 n.Operation = op 27 if cond.Operation == "" { 28 n.Left = cond.Left 29 } else { 30 n.Left = cond 31 } 32 r, ok := right.(Condition) 33 if ok && r.Operation != "" { 34 r.Group = true 35 n.Right = r 36 } else { 37 n.Right = right 38 } 39 return 40 } 41 42 func (cond Condition) name() string { 43 return "condition" 44 } 45 46 func (cond Condition) And(right Node) (n Condition) { 47 return cond.join(AND, right) 48 } 49 50 func (cond Condition) Or(right Node) (n Condition) { 51 return cond.join(OR, right) 52 }