github.com/safing/portbase@v0.19.5/database/query/condition-or.go (about) 1 package query 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/safing/portbase/database/accessor" 8 ) 9 10 // Or combines multiple conditions with a logical _OR_ operator. 11 func Or(conditions ...Condition) Condition { 12 return &orCond{ 13 conditions: conditions, 14 } 15 } 16 17 type orCond struct { 18 conditions []Condition 19 } 20 21 func (c *orCond) complies(acc accessor.Accessor) bool { 22 for _, cond := range c.conditions { 23 if cond.complies(acc) { 24 return true 25 } 26 } 27 return false 28 } 29 30 func (c *orCond) check() (err error) { 31 for _, cond := range c.conditions { 32 err = cond.check() 33 if err != nil { 34 return err 35 } 36 } 37 return nil 38 } 39 40 func (c *orCond) string() string { 41 all := make([]string, 0, len(c.conditions)) 42 for _, cond := range c.conditions { 43 all = append(all, cond.string()) 44 } 45 return fmt.Sprintf("(%s)", strings.Join(all, " or ")) 46 }