github.com/safing/portbase@v0.19.5/database/query/condition-and.go (about)

     1  package query
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/safing/portbase/database/accessor"
     8  )
     9  
    10  // And combines multiple conditions with a logical _AND_ operator.
    11  func And(conditions ...Condition) Condition {
    12  	return &andCond{
    13  		conditions: conditions,
    14  	}
    15  }
    16  
    17  type andCond struct {
    18  	conditions []Condition
    19  }
    20  
    21  func (c *andCond) complies(acc accessor.Accessor) bool {
    22  	for _, cond := range c.conditions {
    23  		if !cond.complies(acc) {
    24  			return false
    25  		}
    26  	}
    27  	return true
    28  }
    29  
    30  func (c *andCond) 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 *andCond) 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, " and "))
    46  }