query

package
v0.24.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2022 License: Apache-2.0, BSD-3-Clause, MIT Imports: 12 Imported by: 12

Documentation

Index

Constants

View Source
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"
	// Contains takes two operands and tests if the left contains the right
	ContainsOperator containsOperator = "contains"
	// 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"
	InSubqueryOperator inSubqueryOperator = "inSubquery"
	// NotInOperator takes two operands and tests if the left is not contained in the right
	NotInOperator notInOperator = "notin"
	// NotExistsSubquery receives a sub-query as single left-operand and checks the sub-query for rows existence. If there're no rows then it will return TRUE, otherwise FALSE.
	// Applicable for usage only with ExistQuery Criterion type
	NotExistsSubquery notExistsSubquery = "notexists"
	// ExistsSubquery receives a sub-query as single left-operand and checks the sub-query for rows existence. If there are any, then it will return TRUE otherwise FALSE.
	// Applicable for usage only with ExistQuery Criterion type
	ExistsSubquery existsSubquery = "exists"
	// 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"
)
View Source
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"
)
View Source
const (
	// Separator is the separator between queries of different type
	Separator string = "and"
)

Variables

View Source
var (
	// Operators returns the supported query operators
	Operators = []Operator{
		EqualsOperator, NotEqualsOperator,
		GreaterThanOperator, LessThanOperator,
		GreaterThanOrEqualOperator, LessThanOrEqualOperator,
		InOperator, NotInOperator, EqualsOrNilOperator, ContainsOperator,
	}
	// CriteriaTypes returns the supported query criteria types
	CriteriaTypes = []CriterionType{FieldQuery, LabelQuery, ExistQuery, Subquery}
)

Functions

func AddCriteria

func AddCriteria(ctx context.Context, newCriteria ...Criterion) (context.Context, error)

AddCriteria adds the given criteria to the context and returns an error if any of the criteria is not valid

func ApplyLabelChangesToLabels added in v0.3.1

func ApplyLabelChangesToLabels(changes types.LabelChanges, labels types.Labels) (types.Labels, types.Labels, types.Labels)

ApplyLabelChangesToLabels applies the specified label changes to the specified labels

func ContextWithCriteria added in v0.1.9

func ContextWithCriteria(ctx context.Context, criteria ...Criterion) (context.Context, error)

ContextWithCriteria returns a new context with given criteria

func LabelChangesFromJSON

func LabelChangesFromJSON(jsonBytes []byte) ([]*types.LabelChange, error)

LabelChangesFromJSON returns the label changes from the json byte array and an error if the changes are not valid

func RetrieveFromCriteria added in v0.10.0

func RetrieveFromCriteria(key string, criteria ...Criterion) string

RetrieveFromCriteria searches for the value (rightOp) of a given key (leftOp) in a set of criteria

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 ByExists added in v0.15.2

func ByExists(subQuery string) Criterion

func ByField

func ByField(operator Operator, leftOp string, rightOp ...string) Criterion

ByField constructs a new criterion for field querying

func ByLabel

func ByLabel(operator Operator, leftOp string, rightOp ...string) Criterion

ByLabel constructs a new criterion for label querying

func ByNotExists added in v0.15.2

func ByNotExists(subQuery string) Criterion

func BySubquery added in v0.22.2

func BySubquery(operator Operator, leftOp string, subQuery string) Criterion

func CriteriaForContext

func CriteriaForContext(ctx context.Context) []Criterion

CriteriaForContext returns the criteria for the given context

func LimitResultBy added in v0.4.0

func LimitResultBy(limit int) Criterion

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

func OrderResultBy(field string, orderType OrderType) Criterion

OrderResultBy constructs a new criterion for result order

func Parse added in v0.7.1

func Parse(criterionType CriterionType, expression string) ([]Criterion, error)

Parse parses the query expression for and builds criteria for the provided type

func (Criterion) Validate

func (c Criterion) Validate() error

Validate the criterion fields

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"
	// ExistQuery denotes that the query should test for the existence of any record in a given sub-query
	ExistQuery CriterionType = "existQuery"
	// InQuery denotes that the query
	Subquery CriterionType = "subQuery"
)

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"
)

type OrderType added in v0.4.0

type OrderType string

OrderType is the type of the order in which result is presented

const (
	// AscOrder orders result in ascending order
	AscOrder OrderType = "ASC"
	// DescOrder orders result in descending order
	DescOrder OrderType = "DESC"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL