query

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: Apache-2.0, BSD-3-Clause, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OpenBracket is the token that denotes the beginning of a multivariate operand
	OpenBracket rune = '['
	// OpenBracket is the token that denotes the end of a multivariate operand
	CloseBracket rune = ']'
	// Separator is the separator between field and label queries
	Separator rune = '|'
	// OperandSeparator is the separator between the operator and the operands
	OperandSeparator rune = ' '
)

Variables

This section is empty.

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 ContextWithCriteria added in v0.1.9

func ContextWithCriteria(ctx context.Context, criteria []Criterion) context.Context

ContextWithCriteria returns a new context with given criteria

Types

type ByLeftOp

type ByLeftOp []Criterion

func (ByLeftOp) Len

func (c ByLeftOp) Len() int

func (ByLeftOp) Less

func (c ByLeftOp) Less(i, j int) bool

func (ByLeftOp) Swap

func (c ByLeftOp) Swap(i, j int)

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 BuildCriteriaFromRequest

func BuildCriteriaFromRequest(request *web.Request) ([]Criterion, error)

BuildCriteriaFromRequest builds criteria for the given request's query params and returns an error if the query is not valid

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 CriteriaForContext

func CriteriaForContext(ctx context.Context) []Criterion

CriteriaForContext returns the criteria for the given context

func (Criterion) Validate

func (c Criterion) Validate() error

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

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 string

Operator is a query operator

const (
	// EqualsOperator takes two operands and tests if they are equal
	EqualsOperator Operator = "="
	// NotEqualsOperator takes two operands and tests if they are not equal
	NotEqualsOperator Operator = "!="
	// GreaterThanOperator takes two operands and tests if the left is greater than the right
	GreaterThanOperator Operator = "gt"
	// LessThanOperator takes two operands and tests if the left is lesser than the right
	LessThanOperator Operator = "lt"
	// InOperator takes two operands and tests if the left is contained in the right
	InOperator Operator = "in"
	// NotInOperator takes two operands and tests if the left is not contained in the right
	NotInOperator Operator = "notin"
	// EqualsOrNilOperator takes two operands and tests if the left is equal to the right, or if the left is nil
	EqualsOrNilOperator Operator = "eqornil"
)

func (Operator) IsMultiVariate

func (op Operator) IsMultiVariate() bool

IsMultiVariate returns true if the operator requires right operand with multiple values

func (Operator) IsNullable

func (op Operator) IsNullable() bool

IsNullable returns true if the operator can check if the left operand is nil

func (Operator) IsNumeric

func (op Operator) IsNumeric() bool

IsNumeric returns true if the operator works only with numeric operands

Jump to

Keyboard shortcuts

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