expr

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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(ctx EvalStack) (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 Cast

type Cast struct {
	Expr   Expr
	CastAs document.ValueType
}

Cast represents the CAST expression.

func (Cast) Eval

func (c Cast) Eval(ctx EvalStack) (document.Value, error)

Eval returns the primary key of the current document.

func (Cast) IsEqual

func (c Cast) IsEqual(other Expr) bool

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

func (Cast) String

func (c Cast) String() string

type EvalStack

type EvalStack struct {
	Tx       *database.Transaction
	Document document.Document
	Params   []Param
	Info     *database.TableInfo
}

EvalStack contains information about the context in which the expression is evaluated. Any of the members can be nil except the transaction.

type Expr

type Expr interface {
	Eval(EvalStack) (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 GetFunc

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

GetFunc return a function expression by name.

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 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 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 FieldSelector

type FieldSelector document.ValuePath

A FieldSelector is a ResultField that extracts a field from a document at a given path.

func (FieldSelector) Eval

func (f FieldSelector) Eval(stack EvalStack) (document.Value, error)

Eval extracts the document from the context and selects the right field. It implements the Expr interface.

func (FieldSelector) IsEqual

func (f FieldSelector) IsEqual(other Expr) bool

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

func (FieldSelector) Name

func (f FieldSelector) Name() string

Name joins the chunks of the fields selector with the . separator.

func (FieldSelector) String

func (f FieldSelector) String() string

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(ctx EvalStack) (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

func (l LiteralExprList) Eval(stack EvalStack) (document.Value, error)

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 DurationValue

func DurationValue(v time.Duration) LiteralValue

DurationValue creates a litteral value of type Duration.

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 NamedParam

type NamedParam string

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

func (NamedParam) Eval

func (p NamedParam) Eval(stack EvalStack) (document.Value, error)

Eval looks up for the parameters in the stack 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(ctx EvalStack) (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(ctx EvalStack) (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(es EvalStack) (document.Value, error)

Eval calls the underlying expression Eval method.

type PositionalParam

type PositionalParam int

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

func (PositionalParam) Eval

func (p PositionalParam) Eval(stack EvalStack) (document.Value, error)

Eval looks up for the parameters in the stack 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.

Jump to

Keyboard shortcuts

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