expr

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinFunctions added in v0.9.0

func BuiltinFunctions() map[string]func(args ...Expr) (Expr, error)

BuiltinFunctions returns default map of builtin functions.

func Equal

func Equal(a, b Expr) bool

Equal reports whether a and b are equal by first calling IsEqual if they have an IsEqual method with this signature:

IsEqual(Expr) bool

If not, it returns whether a and b values are equal.

func IsAndOperator

func IsAndOperator(op Operator) bool

IsAndOperator reports if e is the AND operator.

func IsArithmeticOperator

func IsArithmeticOperator(op Operator) bool

IsArithmeticOperator returns true if e is one of +, -, *, /, %, &, |, or ^ operators.

func IsComparisonOperator

func IsComparisonOperator(op Operator) bool

IsComparisonOperator returns true if e is one of =, !=, >, >=, <, <=, IS, IS NOT, IN, or NOT IN operators.

func IsInOperator

func IsInOperator(e Expr) bool

IsInOperator reports if e is the IN operator.

func IsOrOperator

func IsOrOperator(e Expr) bool

IsOrOperator reports if e is the OR operator.

Types

type AndOp

type AndOp struct {
	// contains filtered or unexported fields
}

AndOp is the And operator.

func (*AndOp) Eval

func (op *AndOp) Eval(env *Environment) (document.Value, error)

Eval implements the Expr interface. It evaluates a and b and returns true if both evaluate to true.

func (AndOp) IsEqual

func (op AndOp) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (AndOp) LeftHand

func (op AndOp) LeftHand() Expr

func (AndOp) Precedence

func (op AndOp) Precedence() int

func (AndOp) RightHand

func (op AndOp) RightHand() Expr

func (AndOp) SetLeftHandExpr

func (op AndOp) SetLeftHandExpr(a Expr)

func (AndOp) SetRightHandExpr

func (op AndOp) SetRightHandExpr(b Expr)

func (*AndOp) String

func (op *AndOp) String() string

String implements the fmt.Stringer interface.

func (AndOp) Token

func (op AndOp) Token() scanner.Token

type AvgAggregator added in v0.9.0

type AvgAggregator struct {
	Fn      *AvgFunc
	Avg     float64
	Counter int64
}

AvgAggregator is an aggregator that returns the average non-null value.

func (*AvgAggregator) Add added in v0.9.0

Add stores the average value of all non-NULL numeric values in the group.

func (*AvgAggregator) Aggregate added in v0.9.0

func (s *AvgAggregator) Aggregate(fb *document.FieldBuffer) error

Aggregate adds a field to the given buffer with the maximum value.

type AvgFunc added in v0.9.0

type AvgFunc struct {
	Expr  Expr
	Alias string
}

AvgFunc is the AVG aggregator function.

func (*AvgFunc) Aggregator added in v0.10.0

func (s *AvgFunc) Aggregator(group document.Value) document.Aggregator

Aggregator implements the planner.AggregatorBuilder interface.

func (*AvgFunc) Eval added in v0.9.0

func (s *AvgFunc) Eval(env *Environment) (document.Value, error)

Eval extracts the average value from the given document and returns it.

func (*AvgFunc) IsEqual added in v0.9.0

func (s *AvgFunc) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*AvgFunc) SetAlias added in v0.9.0

func (s *AvgFunc) SetAlias(alias string)

SetAlias implements the planner.AggregatorBuilder interface.

func (*AvgFunc) String added in v0.9.0

func (s *AvgFunc) String() string

String returns the alias if non-zero, otherwise it returns a string representation of the average expression.

type CastFunc added in v0.8.0

type CastFunc struct {
	Expr   Expr
	CastAs document.ValueType
}

CastFunc represents the CAST expression.

func (CastFunc) Eval added in v0.8.0

func (c CastFunc) Eval(env *Environment) (document.Value, error)

Eval returns the primary key of the current document.

func (CastFunc) IsEqual added in v0.8.0

func (c CastFunc) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (CastFunc) String added in v0.8.0

func (c CastFunc) String() string

type CountAggregator added in v0.8.0

type CountAggregator struct {
	Fn    *CountFunc
	Count int64
}

CountAggregator is an aggregator that counts non-null expressions.

func (*CountAggregator) Add added in v0.8.0

Add increments the counter if the count expression evaluates to a non-null value.

func (*CountAggregator) Aggregate added in v0.8.0

func (c *CountAggregator) Aggregate(fb *document.FieldBuffer) error

Aggregate adds a field to the given buffer with the value of the counter.

type CountFunc added in v0.8.0

type CountFunc struct {
	Expr     Expr
	Alias    string
	Wildcard bool
}

CountFunc is the COUNT aggregator function. It aggregates documents

func (*CountFunc) Aggregator added in v0.10.0

func (c *CountFunc) Aggregator(group document.Value) document.Aggregator

func (*CountFunc) Eval added in v0.8.0

func (c *CountFunc) Eval(env *Environment) (document.Value, error)

func (*CountFunc) IsEqual added in v0.8.0

func (c *CountFunc) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*CountFunc) SetAlias added in v0.8.0

func (c *CountFunc) SetAlias(alias string)

func (*CountFunc) String added in v0.8.0

func (c *CountFunc) String() string

type Environment added in v0.10.0

type Environment struct {
	Params []Param
	Vars   *document.FieldBuffer
	Doc    document.Document

	Outer *Environment
}

Environment contains information about the context in which the expression is evaluated.

func NewEnvironment added in v0.10.0

func NewEnvironment(d document.Document, params ...Param) *Environment

func (*Environment) Clone added in v0.10.0

func (e *Environment) Clone() (*Environment, error)

func (*Environment) Get added in v0.10.0

func (e *Environment) Get(path document.Path) (v document.Value, ok bool)

func (*Environment) GetDocument added in v0.10.0

func (e *Environment) GetDocument() (document.Document, bool)

func (*Environment) GetParamByIndex added in v0.10.0

func (e *Environment) GetParamByIndex(pos int) (document.Value, error)

func (*Environment) GetParamByName added in v0.10.0

func (e *Environment) GetParamByName(name string) (v document.Value, err error)

func (*Environment) Set added in v0.10.0

func (e *Environment) Set(name string, v document.Value)

func (*Environment) SetDocument added in v0.10.0

func (e *Environment) SetDocument(d document.Document)

type Expr

type Expr interface {
	Eval(*Environment) (document.Value, error)
}

An Expr evaluates to a value.

func Add

func Add(a, b Expr) Expr

Add creates an expression thats evaluates to the result of a + b.

func And

func And(a, b Expr) Expr

And creates an expression that evaluates a And b And returns true if both are truthy.

func BitwiseAnd

func BitwiseAnd(a, b Expr) Expr

BitwiseAnd creates an expression thats evaluates to the result of a & b.

func BitwiseOr

func BitwiseOr(a, b Expr) Expr

BitwiseOr creates an expression thats evaluates to the result of a | b.

func BitwiseXor

func BitwiseXor(a, b Expr) Expr

BitwiseXor creates an expression thats evaluates to the result of a ^ b.

func Div

func Div(a, b Expr) Expr

Div creates an expression thats evaluates to the result of a / b.

func Eq

func Eq(a, b Expr) Expr

Eq creates an expression that returns true if a equals b.

func Gt

func Gt(a, b Expr) Expr

Gt creates an expression that returns true if a is greater than b.

func Gte

func Gte(a, b Expr) Expr

Gte creates an expression that returns true if a is greater than or equal to b.

func In

func In(a, b Expr) Expr

In creates an expression that evaluates to the result of a IN b.

func Is

func Is(a, b Expr) Expr

Is creates an expression that evaluates to the result of a IS b.

func IsNot

func IsNot(a, b Expr) Expr

IsNot creates an expression that evaluates to the result of a IS NOT b.

func Like added in v0.9.0

func Like(a, b Expr) Expr

Like creates an expression that evaluates to the result of a LIKE b.

func Lt

func Lt(a, b Expr) Expr

Lt creates an expression that returns true if a is lesser than b.

func Lte

func Lte(a, b Expr) Expr

Lte creates an expression that returns true if a is lesser than or equal to b.

func Mod

func Mod(a, b Expr) Expr

Mod creates an expression thats evaluates to the result of a % b.

func Mul

func Mul(a, b Expr) Expr

Mul creates an expression thats evaluates to the result of a * b.

func Neq

func Neq(a, b Expr) Expr

Neq creates an expression that returns true if a equals b.

func NotIn

func NotIn(a, b Expr) Expr

NotIn creates an expression that evaluates to the result of a NOT IN b.

func NotLike added in v0.9.0

func NotLike(a, b Expr) Expr

NotLike creates an expression that evaluates to the result of a NOT LIKE b.

func Or

func Or(a, b Expr) Expr

Or creates an expression that first evaluates a, returns true if truthy, then evaluates b, returns true if truthy Or false if falsy.

func Sub

func Sub(a, b Expr) Expr

Sub creates an expression thats evaluates to the result of a - b.

type Functions added in v0.9.0

type Functions struct {
	// contains filtered or unexported fields
}

Functions represents a map of builtin SQL functions.

func NewFunctions added in v0.9.0

func NewFunctions() Functions

func (Functions) AddFunc added in v0.9.0

func (f Functions) AddFunc(name string, fn func(args ...Expr) (Expr, error))

AddFunc adds function to the map.

func (Functions) GetFunc added in v0.9.0

func (f Functions) GetFunc(name string, args ...Expr) (Expr, error)

GetFunc return a function expression by name.

type KVPair

type KVPair struct {
	K string
	V Expr
}

KVPair associates an identifier with an expression.

func (KVPair) String

func (p KVPair) String() string

String implements the fmt.Stringer interface.

type KVPairs

type KVPairs []KVPair

KVPairs is a list of KVPair.

func (KVPairs) Eval

func (kvp KVPairs) Eval(env *Environment) (document.Value, error)

Eval turns a list of KVPairs into a document.

func (KVPairs) IsEqual

func (kvp KVPairs) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (KVPairs) String

func (kvp KVPairs) String() string

String implements the fmt.Stringer interface.

type LiteralExprList

type LiteralExprList []Expr

LiteralExprList is a list of expressions.

func (LiteralExprList) Eval

Eval evaluates all the expressions and returns a litteralValueList. It implements the Expr interface.

func (LiteralExprList) IsEqual

func (l LiteralExprList) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (LiteralExprList) String

func (l LiteralExprList) String() string

String implements the fmt.Stringer interface.

type LiteralValue

type LiteralValue document.Value

A LiteralValue represents a litteral value of any type defined by the value package.

func ArrayValue

func ArrayValue(a document.Array) LiteralValue

ArrayValue creates a litteral value of type Array.

func BlobValue

func BlobValue(v []byte) LiteralValue

BlobValue creates a litteral value of type Blob.

func BoolValue

func BoolValue(v bool) LiteralValue

BoolValue creates a litteral value of type Bool.

func DocumentValue

func DocumentValue(d document.Document) LiteralValue

DocumentValue creates a litteral value of type Document.

func DoubleValue added in v0.7.0

func DoubleValue(v float64) LiteralValue

DoubleValue creates a litteral value of type Double.

func IntegerValue added in v0.7.0

func IntegerValue(v int64) LiteralValue

IntegerValue creates a litteral value of type Integer.

func NullValue

func NullValue() LiteralValue

NullValue creates a litteral value of type Null.

func TextValue

func TextValue(v string) LiteralValue

TextValue creates a litteral value of type Text.

func (LiteralValue) Eval

Eval returns l. It implements the Expr interface.

func (LiteralValue) IsEqual

func (v LiteralValue) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (LiteralValue) String

func (v LiteralValue) String() string

String implements the fmt.Stringer interface.

type MaxAggregator added in v0.8.0

type MaxAggregator struct {
	Fn  *MaxFunc
	Max document.Value
}

MaxAggregator is an aggregator that returns the minimum non-null value.

func (*MaxAggregator) Add added in v0.8.0

Add stores the maximum value. Values are compared based on their types, then if the type is equal their value is compared. Numbers are considered of the same type.

func (*MaxAggregator) Aggregate added in v0.8.0

func (m *MaxAggregator) Aggregate(fb *document.FieldBuffer) error

Aggregate adds a field to the given buffer with the maximum value.

type MaxFunc added in v0.8.0

type MaxFunc struct {
	Expr  Expr
	Alias string
}

MaxFunc is the MAX aggregator function.

func (*MaxFunc) Aggregator added in v0.10.0

func (m *MaxFunc) Aggregator(group document.Value) document.Aggregator

Aggregator implements the planner.AggregatorBuilder interface.

func (*MaxFunc) Eval added in v0.8.0

func (m *MaxFunc) Eval(env *Environment) (document.Value, error)

Eval extracts the max value from the given document and returns it.

func (*MaxFunc) IsEqual added in v0.8.0

func (m *MaxFunc) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*MaxFunc) SetAlias added in v0.8.0

func (m *MaxFunc) SetAlias(alias string)

SetAlias implements the planner.AggregatorBuilder interface.

func (*MaxFunc) String added in v0.8.0

func (m *MaxFunc) String() string

String returns the alias if non-zero, otherwise it returns a string representation of the count expression.

type MinAggregator added in v0.8.0

type MinAggregator struct {
	Fn  *MinFunc
	Min document.Value
}

MinAggregator is an aggregator that returns the minimum non-null value.

func (*MinAggregator) Add added in v0.8.0

Add stores the minimum value. Values are compared based on their types, then if the type is equal their value is compared. Numbers are considered of the same type.

func (*MinAggregator) Aggregate added in v0.8.0

func (m *MinAggregator) Aggregate(fb *document.FieldBuffer) error

Aggregate adds a field to the given buffer with the minimum value.

type MinFunc added in v0.8.0

type MinFunc struct {
	Expr  Expr
	Alias string
}

MinFunc is the MIN aggregator function.

func (*MinFunc) Aggregator added in v0.10.0

func (m *MinFunc) Aggregator(group document.Value) document.Aggregator

Aggregator implements the planner.AggregatorBuilder interface.

func (*MinFunc) Eval added in v0.8.0

func (m *MinFunc) Eval(env *Environment) (document.Value, error)

Eval extracts the min value from the given document and returns it.

func (*MinFunc) IsEqual added in v0.8.0

func (m *MinFunc) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*MinFunc) SetAlias added in v0.8.0

func (m *MinFunc) SetAlias(alias string)

SetAlias implements the planner.AggregatorBuilder interface.

func (*MinFunc) String added in v0.8.0

func (m *MinFunc) String() string

String returns the alias if non-zero, otherwise it returns a string representation of the count expression.

type NamedParam

type NamedParam string

NamedParam is an expression which represents the name of a parameter.

func (NamedParam) Eval

func (p NamedParam) Eval(env *Environment) (document.Value, error)

Eval looks up for the parameters in the env for the one that has the same name as p and returns the value.

func (NamedParam) IsEqual

func (p NamedParam) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (NamedParam) String

func (p NamedParam) String() string

String implements the fmt.Stringer interface.

type Operator

type Operator interface {
	Expr

	Precedence() int
	LeftHand() Expr
	RightHand() Expr
	SetLeftHandExpr(Expr)
	SetRightHandExpr(Expr)
	Token() scanner.Token
}

An Operator is a binary expression that takes two operands and executes an operation on them.

type OrOp

type OrOp struct {
	// contains filtered or unexported fields
}

OrOp is the And operator.

func (*OrOp) Eval

func (op *OrOp) Eval(env *Environment) (document.Value, error)

Eval implements the Expr interface. It evaluates a and b and returns true if a or b evalutate to true.

func (OrOp) IsEqual

func (op OrOp) IsEqual(other Expr) bool

Equal compares this expression with the other expression and returns true if they are equal.

func (OrOp) LeftHand

func (op OrOp) LeftHand() Expr

func (OrOp) Precedence

func (op OrOp) Precedence() int

func (OrOp) RightHand

func (op OrOp) RightHand() Expr

func (OrOp) SetLeftHandExpr

func (op OrOp) SetLeftHandExpr(a Expr)

func (OrOp) SetRightHandExpr

func (op OrOp) SetRightHandExpr(b Expr)

func (*OrOp) String

func (op *OrOp) String() string

String implements the fmt.Stringer interface.

func (OrOp) Token

func (op OrOp) Token() scanner.Token

type PKFunc

type PKFunc struct{}

PKFunc represents the pk() function. It returns the primary key of the current document.

func (PKFunc) Eval

func (k PKFunc) Eval(env *Environment) (document.Value, error)

Eval returns the primary key of the current document.

func (PKFunc) IsEqual

func (k PKFunc) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (PKFunc) String

func (k PKFunc) String() string

type Param

type Param struct {
	// Name of the param
	Name string

	// Value is the parameter value.
	Value interface{}
}

A Param represents a parameter passed by the user to the statement.

type Parentheses added in v0.7.0

type Parentheses struct {
	E Expr
}

Parentheses is a special expression which turns any sub-expression as unary. It hides the underlying operator, if any, from the parser so that it doesn't get reordered by precedence.

func (Parentheses) Eval added in v0.7.0

func (p Parentheses) Eval(env *Environment) (document.Value, error)

Eval calls the underlying expression Eval method.

func (Parentheses) IsEqual added in v0.10.0

func (p Parentheses) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

type Path added in v0.9.0

type Path document.Path

A Path is an expression that extracts a value from a document at a given path.

func (Path) Eval added in v0.9.0

func (p Path) Eval(env *Environment) (document.Value, error)

Eval extracts the current value from the environment and returns the value stored at p. It implements the Expr interface.

func (Path) IsEqual added in v0.9.0

func (p Path) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (Path) String added in v0.9.0

func (p Path) String() string

type PositionalParam

type PositionalParam int

PositionalParam is an expression which represents the position of a parameter.

func (PositionalParam) Eval

Eval looks up for the parameters in the env for the one that is has the same position as p and returns the value.

func (PositionalParam) IsEqual

func (p PositionalParam) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (PositionalParam) String

func (p PositionalParam) String() string

String implements the fmt.Stringer interface.

type SumAggregator added in v0.8.0

type SumAggregator struct {
	Fn   *SumFunc
	SumI *int64
	SumF *float64
}

SumAggregator is an aggregator that returns the minimum non-null value.

func (*SumAggregator) Add added in v0.8.0

Add stores the sum of all non-NULL numeric values in the group. The result is an integer value if all summed values are integers. If any of the value is a double, the returned result will be a double.

func (*SumAggregator) Aggregate added in v0.8.0

func (s *SumAggregator) Aggregate(fb *document.FieldBuffer) error

Aggregate adds a field to the given buffer with the maximum value.

type SumFunc added in v0.8.0

type SumFunc struct {
	Expr  Expr
	Alias string
}

SumFunc is the SUM aggregator function.

func (*SumFunc) Aggregator added in v0.10.0

func (s *SumFunc) Aggregator(group document.Value) document.Aggregator

Aggregator implements the planner.AggregatorBuilder interface.

func (*SumFunc) Eval added in v0.8.0

func (s *SumFunc) Eval(env *Environment) (document.Value, error)

Eval extracts the sum value from the given document and returns it.

func (*SumFunc) IsEqual added in v0.8.0

func (s *SumFunc) IsEqual(other Expr) bool

IsEqual compares this expression with the other expression and returns true if they are equal.

func (*SumFunc) SetAlias added in v0.8.0

func (s *SumFunc) SetAlias(alias string)

SetAlias implements the planner.AggregatorBuilder interface.

func (*SumFunc) String added in v0.8.0

func (s *SumFunc) String() string

String returns the alias if non-zero, otherwise it returns a string representation of the count expression.

type Wildcard added in v0.10.0

type Wildcard struct{}

A Wildcard is an expression that iterates over all the fields of a document.

func (Wildcard) Eval added in v0.10.0

func (w Wildcard) Eval(env *Environment) (document.Value, error)

func (Wildcard) String added in v0.10.0

func (w Wildcard) String() string

Jump to

Keyboard shortcuts

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