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

     1  package query
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/safing/portbase/database/accessor"
     8  )
     9  
    10  type existsCondition struct {
    11  	key      string
    12  	operator uint8
    13  }
    14  
    15  func newExistsCondition(key string, operator uint8) *existsCondition {
    16  	return &existsCondition{
    17  		key:      key,
    18  		operator: operator,
    19  	}
    20  }
    21  
    22  func (c *existsCondition) complies(acc accessor.Accessor) bool {
    23  	return acc.Exists(c.key)
    24  }
    25  
    26  func (c *existsCondition) check() error {
    27  	if c.operator == errorPresent {
    28  		return errors.New(c.key)
    29  	}
    30  	return nil
    31  }
    32  
    33  func (c *existsCondition) string() string {
    34  	return fmt.Sprintf("%s %s", escapeString(c.key), getOpName(c.operator))
    35  }