Documentation ¶
Index ¶
- Constants
- Variables
- func AddCriteria(ctx context.Context, newCriteria ...Criterion) (context.Context, error)
- func ApplyLabelChangesToLabels(changes LabelChanges, labels types.Labels) (types.Labels, types.Labels, types.Labels)
- func ContextWithCriteria(ctx context.Context, criteria ...Criterion) (context.Context, error)
- type Criterion
- func ByField(operator Operator, leftOp string, rightOp ...string) Criterion
- func ByLabel(operator Operator, leftOp string, rightOp ...string) Criterion
- func CriteriaForContext(ctx context.Context) []Criterion
- func LimitResultBy(limit int) Criterion
- func NewCriterion(leftOp string, operator Operator, rightOp []string, criteriaType CriterionType) Criterion
- func OrderResultBy(field string, orderType OrderType) Criterion
- func Parse(criterionType CriterionType, expression string) ([]Criterion, error)
- type CriterionType
- type LabelChange
- type LabelChanges
- type LabelOperation
- type Operator
- type OperatorType
- type OrderType
Constants ¶
const ( // EqualsOperator takes two operands and tests if they are equal EqualsOperator eqOperator = "eq" // NotEqualsOperator takes two operands and tests if they are not equal NotEqualsOperator neOperator = "ne" // GreaterThanOperator takes two operands and tests if the left is greater than the right GreaterThanOperator gtOperator = "gt" // GreaterThanOrEqualOperator takes two operands and tests if the left is greater than or equal the right GreaterThanOrEqualOperator geOperator = "ge" // LessThanOperator takes two operands and tests if the left is lesser than the right LessThanOperator ltOperator = "lt" // LessThanOrEqualOperator takes two operands and tests if the left is lesser than or equal the right LessThanOrEqualOperator leOperator = "le" // InOperator takes two operands and tests if the left is contained in the right InOperator inOperator = "in" // NotInOperator takes two operands and tests if the left is not contained in the right NotInOperator notInOperator = "notin" // EqualsOrNilOperator takes two operands and tests if the left is equal to the right, or if the left is nil EqualsOrNilOperator enOperator = "en" NoOperator noOperator = "nop" )
const ( // OrderBy should be used as a left operand in Criterion OrderBy string = "orderBy" // Limit should be used as a left operand in Criterion to signify the Limit string = "limit" )
const ( // Separator is the separator between queries of different type Separator string = "and" )
Variables ¶
var ( // Operators returns the supported query operators Operators = []Operator{ EqualsOperator, NotEqualsOperator, GreaterThanOperator, LessThanOperator, GreaterThanOrEqualOperator, LessThanOrEqualOperator, InOperator, NotInOperator, EqualsOrNilOperator, } // CriteriaTypes returns the supported query criteria types CriteriaTypes = []CriterionType{FieldQuery, LabelQuery} )
Functions ¶
func AddCriteria ¶
AddCriteria adds the given criteria to the context and returns an error if any of the criteria is not valid
Types ¶
type Criterion ¶
type Criterion struct { // LeftOp is the left operand in the query LeftOp string // Operator is the query operator Operator Operator // RightOp is the right operand in the query which can be multivariate RightOp []string // Type is the type of the query Type CriterionType }
Criterion is a single part of a query criteria
func CriteriaForContext ¶
CriteriaForContext returns the criteria for the given context
func LimitResultBy ¶ added in v0.4.0
LimitResultBy constructs a new criterion for limit result with
func NewCriterion ¶ added in v0.7.1
func NewCriterion(leftOp string, operator Operator, rightOp []string, criteriaType CriterionType) Criterion
func OrderResultBy ¶ added in v0.4.0
OrderResultBy constructs a new criterion for result order
type CriterionType ¶
type CriterionType string
CriterionType is a type of criteria to be applied when querying
const ( // FieldQuery denotes that the query should be executed on the entity's fields FieldQuery CriterionType = "fieldQuery" // LabelQuery denotes that the query should be executed on the entity's labels LabelQuery CriterionType = "labelQuery" // ResultQuery is used to further process result ResultQuery CriterionType = "resultQuery" )
type LabelChange ¶
type LabelChange struct { Operation LabelOperation `json:"op"` Key string `json:"key"` Values []string `json:"values"` }
LabelChange represents the changes that should be performed to a label
func LabelChangesFromJSON ¶
func LabelChangesFromJSON(jsonBytes []byte) ([]*LabelChange, error)
LabelChangesFromJSON returns the label changes from the json byte array and an error if the changes are not valid
func (*LabelChange) Validate ¶
func (lc *LabelChange) Validate() error
type LabelChanges ¶ added in v0.1.9
type LabelChanges []*LabelChange
func (*LabelChanges) Validate ¶ added in v0.1.9
func (lc *LabelChanges) Validate() error
type LabelOperation ¶
type LabelOperation string
LabelOperation is an operation to be performed on labels
const ( // AddLabelOperation takes a label and adds it to the entity's labels AddLabelOperation LabelOperation = "add" // AddLabelValuesOperation takes a key and values and adds the values to the label with this key AddLabelValuesOperation LabelOperation = "add_values" // RemoveLabelOperation takes a key and removes the label with this key RemoveLabelOperation LabelOperation = "remove" // RemoveLabelValuesOperation takes a key and values and removes the values from the label with this key RemoveLabelValuesOperation LabelOperation = "remove_values" )
func (LabelOperation) RequiresValues ¶
func (o LabelOperation) RequiresValues() bool
RequiresValues returns true if the operation requires values to be provided
type Operator ¶
type Operator interface { // String returns the text representation of the operator String() string // Type returns the type of the operator Type() OperatorType // IsNullable returns true if the operator allows results with null value in the RHS IsNullable() bool // IsNumeric returns true if the operator works only with numbers IsNumeric() bool }
Operator is a query operator
type OperatorType ¶ added in v0.7.1
type OperatorType string
OperatorType represents the type of the query operator
const ( // UnivariateOperator denotes that the operator expects exactly one variable on the right side UnivariateOperator OperatorType = "univariate" // MultivariateOperator denotes that the operator expects more than one variable on the right side MultivariateOperator OperatorType = "multivariate" )