Documentation ¶
Overview ¶
Package criteria holds a representation of expression trees and code for their manipulation This package serves to decouple the concrete query language from the execution of the queries against the database
Index ¶
- func IterateParents(exp Expression, f func(Expression) bool)
- func IteratePostOrder(exp Expression, visitorFunction func(exp Expression) bool)
- type AndExpression
- type BinaryExpression
- type EqualsExpression
- type Expression
- func And(left Expression, right Expression) Expression
- func Equals(left Expression, right Expression) Expression
- func Field(id string) Expression
- func IsNull(name string) Expression
- func Literal(value interface{}) Expression
- func Not(left Expression, right Expression) Expression
- func Or(left Expression, right Expression) Expression
- func Parameter() Expression
- type ExpressionVisitor
- type FieldExpression
- type IsNullExpression
- type LiteralExpression
- type NotExpression
- type OrExpression
- type ParameterExpression
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IterateParents ¶
func IterateParents(exp Expression, f func(Expression) bool)
IterateParents calls f for every member of the parent chain Stops iterating if f returns false
func IteratePostOrder ¶
func IteratePostOrder(exp Expression, visitorFunction func(exp Expression) bool)
IteratePostOrder walks the expression tree in depth-first, left to right order The iteration stops if visitorFunction returns false
Types ¶
type AndExpression ¶
type AndExpression struct {
// contains filtered or unexported fields
}
AndExpression represents the conjunction operation of two terms
func (*AndExpression) Accept ¶
func (t *AndExpression) Accept(visitor ExpressionVisitor) interface{}
Accept implements ExpressionVisitor
func (*AndExpression) Left ¶
func (exp *AndExpression) Left() Expression
Left implements BinaryExpression
func (*AndExpression) Right ¶
func (exp *AndExpression) Right() Expression
Right implements BinaryExpression
type BinaryExpression ¶
type BinaryExpression interface { Expression Left() Expression Right() Expression }
BinaryExpression represents expressions with 2 children This could be generalized to n-ary expressions, but that is not necessary right now
type EqualsExpression ¶
type EqualsExpression struct {
// contains filtered or unexported fields
}
EqualsExpression represents the equality operator
func (*EqualsExpression) Accept ¶
func (t *EqualsExpression) Accept(visitor ExpressionVisitor) interface{}
Accept implements ExpressionVisitor
func (*EqualsExpression) Left ¶
func (exp *EqualsExpression) Left() Expression
Left implements BinaryExpression
func (*EqualsExpression) Right ¶
func (exp *EqualsExpression) Right() Expression
Right implements BinaryExpression
type Expression ¶
type Expression interface { // Accept calls the visitor callback of the appropriate type Accept(visitor ExpressionVisitor) interface{} // SetAnnotation puts the given annotation on the expression SetAnnotation(key string, value interface{}) // Annotation reads back values set with SetAnnotation Annotation(key string) interface{} // Returns the parent expression or nil Parent() Expression // contains filtered or unexported methods }
Expression is used to express conditions for selecting an entity
func Equals ¶
func Equals(left Expression, right Expression) Expression
Equals constructs an EqualsExpression
type ExpressionVisitor ¶
type ExpressionVisitor interface { Field(t *FieldExpression) interface{} And(a *AndExpression) interface{} Or(a *OrExpression) interface{} Equals(e *EqualsExpression) interface{} Parameter(v *ParameterExpression) interface{} Literal(c *LiteralExpression) interface{} Not(e *NotExpression) interface{} IsNull(e *IsNullExpression) interface{} }
ExpressionVisitor is an implementation of the visitor pattern for expressions
type FieldExpression ¶
type FieldExpression struct { FieldName string // contains filtered or unexported fields }
FieldExpression represents access to a field of the tested object
func (*FieldExpression) Accept ¶
func (t *FieldExpression) Accept(visitor ExpressionVisitor) interface{}
Accept implements ExpressionVisitor
func (*FieldExpression) Annotation ¶
func (exp *FieldExpression) Annotation(key string) interface{}
func (*FieldExpression) Parent ¶
func (exp *FieldExpression) Parent() Expression
func (*FieldExpression) SetAnnotation ¶
func (exp *FieldExpression) SetAnnotation(key string, value interface{})
type IsNullExpression ¶
type IsNullExpression struct { FieldName string // contains filtered or unexported fields }
IsNullExpression represents the IS operator with NULL value
func (*IsNullExpression) Accept ¶
func (t *IsNullExpression) Accept(visitor ExpressionVisitor) interface{}
Accept implements ExpressionVisitor
func (*IsNullExpression) Annotation ¶
func (exp *IsNullExpression) Annotation(key string) interface{}
func (*IsNullExpression) Parent ¶
func (exp *IsNullExpression) Parent() Expression
func (*IsNullExpression) SetAnnotation ¶
func (exp *IsNullExpression) SetAnnotation(key string, value interface{})
type LiteralExpression ¶
type LiteralExpression struct { Value interface{} // contains filtered or unexported fields }
A LiteralExpression represents a single constant value in the expression, think "5" or "asdf" the type of literals is not restricted at this level, but compilers or interpreters will have limitations on what they handle
func (*LiteralExpression) Accept ¶
func (t *LiteralExpression) Accept(visitor ExpressionVisitor) interface{}
Accept implements ExpressionVisitor
func (*LiteralExpression) Annotation ¶
func (exp *LiteralExpression) Annotation(key string) interface{}
func (*LiteralExpression) Parent ¶
func (exp *LiteralExpression) Parent() Expression
func (*LiteralExpression) SetAnnotation ¶
func (exp *LiteralExpression) SetAnnotation(key string, value interface{})
type NotExpression ¶
type NotExpression struct {
// contains filtered or unexported fields
}
NotExpression represents the negation operator
func (*NotExpression) Accept ¶
func (t *NotExpression) Accept(visitor ExpressionVisitor) interface{}
Accept implements ExpressionVisitor
func (*NotExpression) Left ¶
func (exp *NotExpression) Left() Expression
Left implements BinaryExpression
func (*NotExpression) Right ¶
func (exp *NotExpression) Right() Expression
Right implements BinaryExpression
type OrExpression ¶
type OrExpression struct {
// contains filtered or unexported fields
}
OrExpression represents the disjunction operation of two terms
func (*OrExpression) Accept ¶
func (t *OrExpression) Accept(visitor ExpressionVisitor) interface{}
Accept implements ExpressionVisitor
func (*OrExpression) Left ¶
func (exp *OrExpression) Left() Expression
Left implements BinaryExpression
func (*OrExpression) Right ¶
func (exp *OrExpression) Right() Expression
Right implements BinaryExpression
type ParameterExpression ¶
type ParameterExpression struct {
// contains filtered or unexported fields
}
A ParameterExpression represents a parameter to be passed upon evaluation of the expression
func (*ParameterExpression) Accept ¶
func (t *ParameterExpression) Accept(visitor ExpressionVisitor) interface{}
Accept implements ExpressionVisitor
func (*ParameterExpression) Annotation ¶
func (exp *ParameterExpression) Annotation(key string) interface{}
func (*ParameterExpression) Parent ¶
func (exp *ParameterExpression) Parent() Expression
func (*ParameterExpression) SetAnnotation ¶
func (exp *ParameterExpression) SetAnnotation(key string, value interface{})