go-dfl: github.com/spatialcurrent/go-dfl/dfl Index | Files | Directories

package dfl

import "github.com/spatialcurrent/go-dfl/dfl"

Package dfl provides the interfaces, embedded structs, and implementing code for parsing, compiling, and evaluating Dynamic Filter Language (DFL) expressions.

Usage

You can import dfl as a package into your own Go project or use the command line interface. A common architecture is to have a client application generate a DFL expression string and submit to a Go application using a rest interface.

import (
  "github.com/spatialcurrent/go-dfl/dfl"
)
root, err := dfl.Parse("<YOUR EXPRESSION>")
if err != nil {
  panic(err)
}
root = root.Compile()  // Flattens tree for performance if possible.
result := root.Evaluate(Context{<YOUR KEY:VALUE Context>})

DFL

DFL is another query or filter language like SQL, CQL, or ECQL. DFL aims to be easily understood by humans in a variety of contexts, such as in a url, in an editor, or in a python terminal. The principals are as follows:

1.  Easy to Read - The "@" in front of every attribute.
2.  Clean - Quotes are optional (unless required because of spaces in an element)
3.  Strict Execution Path - Use of parentheses is strongly encouraged o maximize performance over large datasets.
4.  Dynamically typed - Operators support multiple types and try to cast if possible.  Fails hard if not valid.
5.  Embeddable - Easily written in other languages, such as Python, Javascript, or Shell, without endless worry about escaping.

DFL aims to cover a wide variety of filters while keeping the language expressive and easy to read. DFL currently supports:

* Boolean: Not, And, Or
* Numeric: LessThan, LessThanOrEqual, Equal, NotEqual, GreaterThan, GreaterThanOrEqual, Add, Subtract
* String: Like, ILike, In
* Time: Before, After
* Array/Set: In
* Function: Function

Command Line Interface

See the github.com/go-dfl/cmd/dfl package for a command line tool for testing DFL expressions.

- https://godoc.org/github.com/spatialcurrent/go-dfl/dfl

Projects

go-dfl is used by the railgun and go-osm project.

- https://godoc.org/github.com/spatialcurrent/railgun/railgun
- https://godoc.org/github.com/spatialcurrent/go-osm/osm
- https://godoc.org/github.com/spatialcurrent/go-dfl/dfl

Examples

Below are some simple examples.

import (
  "github.com/spatialcurrent/go-dfl/dfl"
)
root, err := dfl.Parse("(@amenity in [restaurant, bar]) or (@craft in [brewery, distillery])")
if err != nil {
  panic(err)
}
root = root.Compile()
valid := root.Evaluate(Context{"amenity": "bar", "name": "John's Whiskey Bar"})

Index

Package Files

Add.go After.go And.go Array.go Assign.go AssignAdd.go AssignMultiply.go AssignSubtract.go AttachLeft.go Attribute.go Before.go BinaryOperator.go Coalesce.go CompareNumbers.go CompareStrings.go CompareTimes.go Concat.go Context.go Dictionary.go Divide.go DivideNumbers.go Equal.go ErrParseTernary.go ErrorEvaluate.go EscapeString.go EvaluateArray.go EvaluateBool.go EvaluateFloat64.go EvaluateInt.go EvaluateMap.go EvaluateString.go Extract.go FormatList.go FormatNodes.go FormatSql.go Function.go FunctionMap.go GreaterThan.go GreaterThanOrEqual.go IIn.go ILike.go In.go LessThan.go LessThanOrEqual.go Like.go Literal.go MultiOperator.go Multiply.go MustParseCompile.go MustParseCompileEvaluate.go Node.go Not.go NotEqual.go Null.go NumericBinaryOperator.go Or.go Parse.go ParseAndCompileExpressions.go ParseArray.go ParseAttribute.go ParseCompile.go ParseCompileEvaluate.go ParseCompileEvaluateInt.go ParseCompileEvaluateMap.go ParseCompileEvaluateString.go ParseFunction.go ParseKeyValue.go ParseList.go ParseListOrKeyValue.go ParseLiteral.go ParseSetOrDictionary.go ParseSub.go ParseVariable.go Pipe.go Pipeline.go Print.go Reader.go RemoveComments.go Set.go StringSet.go Subtract.go TemporalBinaryOperator.go TernaryOperator.go TestCase.go TryConvertArray.go TryConvertMap.go TryConvertString.go TryFormatLiteral.go UnaryOperator.go UnescapeString.go Variable.go Version.go Within.go WithinRange.go Xor.go dfl.go functions.go reflect.go

Variables

var DefaultFunctionMap = NewFuntionMapWithDefaults()
var DefaultQuotes = []string{"'", "\"", "`"}
var DefaultTab = "  "
var NoContext = map[string]interface{}{}
var NoVars = map[string]interface{}{}
var SqlArrayPrefix = "{"
var SqlArraySuffix = "}"
var SqlQuote = "'"
var Version = "0.0.11"

func AttachLeft Uses

func AttachLeft(root Node, left Node) error

AttachLeft attaches the left Node as the left child node to the parent root Node.

func CompareNumbers Uses

func CompareNumbers(a interface{}, b interface{}) (int, error)

CompareNumbers compares parameter a and parameter b. The parameters may be of type uint8, int, int64, or float64. If a > b, then returns 1. If a < b, then returns -1. If a == b, then return 0.

func CompareStrings Uses

func CompareStrings(lvs string, rvs string) (bool, error)

CompareStrings compares parameter a and parameter b. The parameters must be of type string. Returns true if a like b.

func CompareTimes Uses

func CompareTimes(a interface{}, b interface{}) (int, error)

CompareTimes compares parameter a and parameter b. The parameters may be of type string, time.Time, or *time.Time. If a is after b, then returns 1. If a is before b, then returns -1. If a is at the same time as b, then return 0.

func CreateGroups Uses

func CreateGroups(depth int) interface{}

func DivideNumbers Uses

func DivideNumbers(a interface{}, b interface{}) (interface{}, error)

DivideNumbers divides the first number by the second number and returns the results. The parameters can be an int, int64, or float64. The parameters will be cast as applicable. For example you can divide two integers with

total := DivideNumbers(1, 2)

or you could divide an int with a float64.

total := DivideNumbers(4, 3.2)

func EscapeString Uses

func EscapeString(in string) string

func EvaluateArray Uses

func EvaluateArray(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

EvaluateArray returns the array/slice value of a node given a context. If the result is not an array or slice, then returns an error.

func EvaluateBool Uses

func EvaluateBool(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, bool, error)

EvaluateBool returns the boolean value of a node given a context. If the result is not a bool, then returns an error.

func EvaluateFloat64 Uses

func EvaluateFloat64(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, float64, error)

EvaluateFloat64 returns the float64 value of a node given a context. If the result is not a float64, then returns an error.

func EvaluateInt Uses

func EvaluateInt(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, int, error)

EvaluateInt returns the int value of a node given a context. If the result is not an int, then returns an error.

func EvaluateMap Uses

func EvaluateMap(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

EvaluateMap returns the map value of a node given a context. If the result is not a map, then returns an error.

func EvaluateString Uses

func EvaluateString(n Node, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, string, error)

EvaluateString returns the string value of a node given a context. If the result is not a string, then returns an error.

func Extract Uses

func Extract(path string, obj interface{}, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (interface{}, error)

Extract is a function to extract a value from an object. Extract supports a standard dot (.) and null-safe (?.) indexing. Extract also supports wildcard indexing using *. Extract also support array indexing, including [A], [A:B], [A:], and [:B].

func FormatList Uses

func FormatList(values []string, delim string, pretty bool, tabs int) string

func FormatNodes Uses

func FormatNodes(nodes []Node, quotes []string, pretty bool, tabs int) []string

FormatNodes formats an array of nodes to a string.

func FormatSql Uses

func FormatSql(value interface{}, pretty bool, tabs int) string

FormatSQL formats an object as a SQL string

func MustParseCompileEvaluate Uses

func MustParseCompileEvaluate(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{})

MustParseCompileEvaluate parses the expression, compiles the node, and evaluates on the given context. Panics if any error.

func ParseAndCompileExpressions Uses

func ParseAndCompileExpressions(expressions map[string]string) (map[string]Node, error)

ParseAndCompileExpressions is a usability function to parse and compile multiple expressions.

func ParseCompileEvaluate Uses

func ParseCompileEvaluate(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

ParseCompileEvaluate parses the expression, compiles the node, and evaluates on the given context.

func ParseCompileEvaluateInt Uses

func ParseCompileEvaluateInt(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, int, error)

ParseCompileEvaluateInt parses the expression, compiles the node, evaluates on the given context, and returns a result of type int if valid, otherwise returns and error.

func ParseCompileEvaluateMap Uses

func ParseCompileEvaluateMap(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

ParseCompileEvaluateMap parses the expression, compiles the node, evaluates on the given context, and returns a result of kind map if valid, otherwise returns and error.

func ParseCompileEvaluateString Uses

func ParseCompileEvaluateString(exp string, vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, string, error)

ParseCompileEvaluateString parses the expression, compiles the node, evaluates on the given context, and returns a result of kind string if valid, otherwise returns and error.

func ParseKeyValue Uses

func ParseKeyValue(in string) (map[Node]Node, error)

ParseKeyValue parses a sequence of key value pairs

func RemoveComments Uses

func RemoveComments(in string) string

RemoveComments removes comments from a multi-line dfl expression

func TryConvertArray Uses

func TryConvertArray(a []interface{}) interface{}

TryConvertArray attempts to convert the []interface{} array into []int, []int64, []float64, or []string, if possible.

func TryConvertMap Uses

func TryConvertMap(m interface{}) interface{}

TryConvertMap attempts to convert the interface{} map into a typed version

func TryConvertString Uses

func TryConvertString(s string) interface{}

TryConvertString attempts to parse the string parameter s into an appropriate literal value of type string, bool, int, float64, or time.Time. The functions evaluates the following rules in order. It returns the first success. The rules are:

1. "null", "none", "" => ""
2. "true" => true (bool)
3. "false" => false (bool)
4. "0.234" => float64
5. 131238 => int
6. time.Parse(time.RFC3339Nano, s)
7. time.Parse(time.RFC3339, s)
8. time.Parse("2006-01-02", s)
9. If no rules pass without error, then just return the input value

For example:

TryConvertString("a") => "a" (string)
TryConvertString("true") => true (bool)
TryConvertString("123.31") => 123.31 (float64)
TryConvertString("4") => 4 (int)
TryConvertString("2018-05-01") => 2018-05-01T00:00:00Z (time.Time)

func TryFormatLiteral Uses

func TryFormatLiteral(value interface{}, quotes []string, pretty bool, tabs int) string

func UnescapeString Uses

func UnescapeString(in string) string

UnescapeString unescapes a string

- \\ => \
- \n => new line
- \r => carriage return
- \t => horizontal tab
- \s => space
- \u1234 => unicode value

func WithinRange Uses

func WithinRange(value interface{}, start interface{}, end interface{}) (bool, error)

WithinRange returns true if value is in the range [start, end]

type Add Uses

type Add struct {
    *BinaryOperator
}

Add is a BinaryOperator that represents the addition of two nodes.

func (Add) Compile Uses

func (a Add) Compile() Node

Compile returns a compiled version of this node. If the left and right values are both compiled as literals, then returns the compiled Literal with that value set. Otherwise returns a clone of this node.

func (Add) Dfl Uses

func (a Add) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL representation of this node as a string

func (Add) Evaluate Uses

func (a Add) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

Evaluate returns the value of this node given Context ctx, and an error if any.

func (Add) Map Uses

func (a Add) Map() map[string]interface{}

Map returns a map representation of this node.

func (Add) Sql Uses

func (a Add) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node.

type After Uses

type After struct {
    *TemporalBinaryOperator // Extends the TemporalBinaryOperator struct
}

After is a TemporalBinaryOperator evaluating to true if the left value is after the right value. The left and right values must be string, time.Time, or *time.Time.

func (After) Compile Uses

func (a After) Compile() Node

func (After) Dfl Uses

func (a After) Dfl(quotes []string, pretty bool, tabs int) string

func (After) Evaluate Uses

func (a After) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (After) Map Uses

func (a After) Map() map[string]interface{}

func (After) Sql Uses

func (a After) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type And Uses

type And struct {
    *BinaryOperator
}

And is a BinaryOperator which represents the logical boolean AND operation of left and right values.

func (And) Compile Uses

func (a And) Compile() Node

Compile returns a compiled version of this node. If the left value and right value are both compiled as Literals, then returns the logical boolean AND operation of the left and right value. Otherwise, returns a clone.

func (And) Dfl Uses

func (a And) Dfl(quotes []string, pretty bool, tabs int) string

func (And) Evaluate Uses

func (a And) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (And) Map Uses

func (a And) Map() map[string]interface{}

func (And) Sql Uses

func (a And) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Array Uses

type Array struct {
    Nodes []Node
}

Array is a Node representing an array of values, which can be either a Literal or Attribute.

func (Array) Attributes Uses

func (a Array) Attributes() []string

func (Array) Compile Uses

func (a Array) Compile() Node

Compile returns a compiled version of this node. If all the values of an Set are literals, returns a single Literal with the corresponding array as its value. Otherwise returns the original node..

func (Array) Dfl Uses

func (a Array) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL representation of this node as a string

func (Array) Evaluate Uses

func (a Array) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Array) Len Uses

func (a Array) Len() int

Len returns the length of the underlying array.

func (Array) Map Uses

func (a Array) Map() map[string]interface{}

func (Array) Sql Uses

func (a Array) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

func (Array) Variables Uses

func (a Array) Variables() []string

type Assign Uses

type Assign struct {
    *BinaryOperator
}

Assign is a BinaryOperator which sets the value of the right side to the attribute or variable defined by the left side.

func (Assign) Compile Uses

func (a Assign) Compile() Node

Compile returns a compiled version of this node.

func (Assign) Dfl Uses

func (a Assign) Dfl(quotes []string, pretty bool, tabs int) string

func (Assign) Evaluate Uses

func (a Assign) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Assign) Map Uses

func (a Assign) Map() map[string]interface{}

func (Assign) Sql Uses

func (a Assign) Sql(pretty bool, tabs int) string

type AssignAdd Uses

type AssignAdd struct {
    *BinaryOperator
}

AssignAdd is a BinaryOperator which sets the added value of the left side and right side to the attribute or variable defined by the left side.

func (AssignAdd) Compile Uses

func (a AssignAdd) Compile() Node

Compile returns a compiled version of this node.

func (AssignAdd) Dfl Uses

func (a AssignAdd) Dfl(quotes []string, pretty bool, tabs int) string

func (AssignAdd) Evaluate Uses

func (a AssignAdd) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (AssignAdd) Map Uses

func (a AssignAdd) Map() map[string]interface{}

func (AssignAdd) Sql Uses

func (a AssignAdd) Sql(pretty bool, tabs int) string

type AssignMultiply Uses

type AssignMultiply struct {
    *BinaryOperator
}

AssignMultiply is a BinaryOperator which sets the multiplied value of the left side and right side to the attribute or variable defined by the left side.

func (AssignMultiply) Compile Uses

func (a AssignMultiply) Compile() Node

Compile returns a compiled version of this node.

func (AssignMultiply) Dfl Uses

func (a AssignMultiply) Dfl(quotes []string, pretty bool, tabs int) string

func (AssignMultiply) Evaluate Uses

func (a AssignMultiply) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (AssignMultiply) Map Uses

func (a AssignMultiply) Map() map[string]interface{}

func (AssignMultiply) Sql Uses

func (a AssignMultiply) Sql(pretty bool, tabs int) string

type AssignSubtract Uses

type AssignSubtract struct {
    *BinaryOperator
}

AssignSubtract is a BinaryOperator which sets the value of the left side subtracted by the right side to the attribute or variable defined by the left side.

func (AssignSubtract) Compile Uses

func (a AssignSubtract) Compile() Node

Compile returns a compiled version of this node.

func (AssignSubtract) Dfl Uses

func (a AssignSubtract) Dfl(quotes []string, pretty bool, tabs int) string

func (AssignSubtract) Evaluate Uses

func (a AssignSubtract) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (AssignSubtract) Map Uses

func (a AssignSubtract) Map() map[string]interface{}

func (AssignSubtract) Sql Uses

func (a AssignSubtract) Sql(pretty bool, tabs int) string

type Attribute Uses

type Attribute struct {
    Name string
}

Attribute is a Node representing the value of an attribute in the context map. Attributes start with a "@" and follow with the name or full path into the object if multiple levels deep. For example, @a and @a.b.c.d. You can also use a null-safe operator, e.g., @a?.b?.c?.d

func (Attribute) Attributes Uses

func (a Attribute) Attributes() []string

func (Attribute) Compile Uses

func (a Attribute) Compile() Node

func (Attribute) Dfl Uses

func (a Attribute) Dfl(quotes []string, pretty bool, tabs int) string

func (Attribute) Evaluate Uses

func (a Attribute) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Attribute) Map Uses

func (a Attribute) Map() map[string]interface{}

func (Attribute) Sql Uses

func (a Attribute) Sql(pretty bool, tabs int) string

func (Attribute) Variables Uses

func (a Attribute) Variables() []string

type Before Uses

type Before struct {
    *TemporalBinaryOperator // Extends the TemporalBinaryOperator struct
}

Before is a TemporalBinaryOperator evaluating to true if the left value is before the right value. The left and right values must be string, time.Time, or *time.Time.

func (Before) Compile Uses

func (b Before) Compile() Node

func (Before) Dfl Uses

func (b Before) Dfl(quotes []string, pretty bool, tabs int) string

func (Before) Evaluate Uses

func (b Before) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Before) Map Uses

func (b Before) Map() map[string]interface{}

func (Before) Sql Uses

func (b Before) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type BinaryOperator Uses

type BinaryOperator struct {
    Left  Node
    Right Node
}

BinaryOperator is a DFL Node that represents the binary operator of a left value and right value. This struct functions as an embedded struct for many comparator operations.

func (BinaryOperator) Attributes Uses

func (bo BinaryOperator) Attributes() []string

Attributes returns a slice of all attributes used in the evaluation of this node, including a children nodes. Attributes de-duplicates values from the left node and right node using a set.

func (BinaryOperator) Builder Uses

func (bo BinaryOperator) Builder(operator string, quotes []string, tabs int) builder.Builder

func (BinaryOperator) Dfl Uses

func (bo BinaryOperator) Dfl(operator string, quotes []string, pretty bool, tabs int) string

func (BinaryOperator) EvaluateLeftAndRight Uses

func (bo BinaryOperator) EvaluateLeftAndRight(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, interface{}, error)

EvaluateLeftAndRight evaluates the value of the left node and right node given a context map (ctx) and function map (funcs). Returns a 3 value tuple of left value, right value, and error.

func (BinaryOperator) Map Uses

func (bo BinaryOperator) Map(operator string, left Node, right Node) map[string]interface{}

func (BinaryOperator) Sql Uses

func (bo BinaryOperator) Sql(operator string, pretty bool, tabs int) string

func (BinaryOperator) Variables Uses

func (bo BinaryOperator) Variables() []string

Variables returns a slice of all variables used in the evaluation of this node, including a children nodes. Attributes de-duplicates values from the left node and right node using a set.

type Coalesce Uses

type Coalesce struct {
    *BinaryOperator
}

Coalesce is a BinaryOperator which returns the left value if not null otherwise the right value.

func (Coalesce) Compile Uses

func (c Coalesce) Compile() Node

Compile returns a compiled version of this node. If the left value is compiled as a Literal, then returns the left value. Otherwise, returns a clone.

func (Coalesce) Dfl Uses

func (c Coalesce) Dfl(quotes []string, pretty bool, tabs int) string

func (Coalesce) Evaluate Uses

func (c Coalesce) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Coalesce) Map Uses

func (c Coalesce) Map() map[string]interface{}

func (Coalesce) Sql Uses

func (c Coalesce) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Concat Uses

type Concat struct {
    *MultiOperator
}

Concat concatenates the string representation of all the arguments

func (Concat) Compile Uses

func (c Concat) Compile() Node

func (Concat) Dfl Uses

func (c Concat) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL expression representation of this node.

func (Concat) Evaluate Uses

func (c Concat) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Concat) Map Uses

func (c Concat) Map() map[string]interface{}

func (Concat) Sql Uses

func (c Concat) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

func (Concat) Suffix Uses

func (c Concat) Suffix() string

Suffix returns the suffix of the result of evaluation, if the last argument is a Literal. If the last argument is not a literal, then returns an empty string.

type Context Uses

type Context struct {
    Data map[string]interface{}
}

Context is a simple alias for a map[string]interface{} that is used for containing the context for evaluating a DFL Node. The values in a context are essentially the input parameters for a DFL expression and match up with the Attribute. The Context is built from the trailing command line arguments. For example the arguments from the following command line

./dfl -filter "(@amenity like bar) and (open > 0)" amenity=bar popularity=10 open=1

Would be interpreted as the following Context

ctx := Context{"amenity": "bar", "popularity": 10, "open": 1}

func (*Context) Get Uses

func (c *Context) Get(key string) interface{}

func (*Context) Has Uses

func (c *Context) Has(key string) bool

func (*Context) Len Uses

func (c *Context) Len() int

func (*Context) Set Uses

func (c *Context) Set(key string, value interface{})

func (*Context) Values Uses

func (c *Context) Values() []interface{}

type Dictionary Uses

type Dictionary struct {
    Nodes map[Node]Node
}

Dictionary is a Node representing a dictionary of key value pairs.

func (Dictionary) Attributes Uses

func (d Dictionary) Attributes() []string

func (Dictionary) Compile Uses

func (d Dictionary) Compile() Node

Compile returns a compiled version of this node.

func (Dictionary) Dfl Uses

func (d Dictionary) Dfl(quotes []string, pretty bool, tabs int) string

func (Dictionary) Evaluate Uses

func (d Dictionary) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Dictionary) Len Uses

func (d Dictionary) Len() int

Len returns the length of the underlying array.

func (Dictionary) Map Uses

func (d Dictionary) Map() map[string]interface{}

func (Dictionary) Sql Uses

func (d Dictionary) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

func (Dictionary) Variables Uses

func (d Dictionary) Variables() []string

type Divide Uses

type Divide struct {
    *NumericBinaryOperator
}

Divide is a NumericBinaryOperator that represents the mathematical division of two nodes.

func (Divide) Compile Uses

func (d Divide) Compile() Node

Compile returns a compiled version of this node.

func (Divide) Dfl Uses

func (d Divide) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL representation of this node as a string

func (Divide) Evaluate Uses

func (d Divide) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

Evaluate evaluates this node given the variables "vars" and context "ctx" and returns the output, and an error if any.

func (Divide) Map Uses

func (d Divide) Map() map[string]interface{}

Map returns a map representation of this node.

func (Divide) Sql Uses

func (d Divide) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Equal Uses

type Equal struct {
    *BinaryOperator
}

Equal is a BinaryOperator that evaluating to true if parameter a is equal to parameter b. The parameters may be of type int, int64, or float64.

func (Equal) Compile Uses

func (e Equal) Compile() Node

func (Equal) Dfl Uses

func (e Equal) Dfl(quotes []string, pretty bool, tabs int) string

func (Equal) Evaluate Uses

func (e Equal) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Equal) Map Uses

func (e Equal) Map() map[string]interface{}

func (Equal) Sql Uses

func (e Equal) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type ErrParseTernary Uses

type ErrParseTernary struct {
    Original  string // original
    Condition string // the condition
    True      string // the true value
    False     string // the false value
}

ErrParseTernary is an error when parsing ternary expressions.

func (ErrParseTernary) Error Uses

func (e ErrParseTernary) Error() string

Error returns the error as a string.

type ErrorEvaluate Uses

type ErrorEvaluate struct {
    Node   Node     // the name of the Function
    Quotes []string // the quotes to use
}

ErrorEvaluate is an error returned when an error occurs during evaluation of a Node.

func (ErrorEvaluate) Error Uses

func (e ErrorEvaluate) Error() string

Error returns the error as a string.

type Function Uses

type Function struct {
    *MultiOperator
    Name string `json:"name" bson:"name" yaml:"name" hcl:"name"` // name of the function
}

Function is a refrenced function in a DFL filter. The actual function in a given FunctionMap is derefernced by name.

func (Function) Compile Uses

func (f Function) Compile() Node

func (Function) Dfl Uses

func (f Function) Dfl(quotes []string, pretty bool, tabs int) string

func (Function) Evaluate Uses

func (f Function) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Function) Map Uses

func (f Function) Map() map[string]interface{}

func (Function) Sql Uses

func (f Function) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type FunctionMap Uses

type FunctionMap map[string]func(FunctionMap, map[string]interface{}, interface{}, []interface{}, []string) (interface{}, error)

FunctionMap is a map of functions by string that are reference by name in the Function Node.

func NewFuntionMapWithDefaults Uses

func NewFuntionMapWithDefaults() FunctionMap

type GreaterThan Uses

type GreaterThan struct {
    *NumericBinaryOperator
}

GreaterThan is a NumericBinaryOperator that evaluating to true if parameter a is greater than parameter b. The parameters may be of type int, int64, or float64.

func (GreaterThan) Compile Uses

func (gt GreaterThan) Compile() Node

func (GreaterThan) Dfl Uses

func (gt GreaterThan) Dfl(quotes []string, pretty bool, tabs int) string

func (GreaterThan) Evaluate Uses

func (gt GreaterThan) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (GreaterThan) Map Uses

func (gt GreaterThan) Map() map[string]interface{}

func (GreaterThan) Sql Uses

func (gt GreaterThan) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type GreaterThanOrEqual Uses

type GreaterThanOrEqual struct {
    *NumericBinaryOperator
}

GreaterThanOrEqual is a NumericBinaryOperator that evaluating to true if parameter a is greater than or equal to parameter b. The parameters may be of type int, int64, or float64.

func (GreaterThanOrEqual) Compile Uses

func (gte GreaterThanOrEqual) Compile() Node

func (GreaterThanOrEqual) Dfl Uses

func (gte GreaterThanOrEqual) Dfl(quotes []string, pretty bool, tabs int) string

func (GreaterThanOrEqual) Evaluate Uses

func (gte GreaterThanOrEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (GreaterThanOrEqual) Map Uses

func (gte GreaterThanOrEqual) Map() map[string]interface{}

func (GreaterThanOrEqual) Sql Uses

func (gte GreaterThanOrEqual) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type IIn Uses

type IIn struct {
    *BinaryOperator
}

In is a BinaryOperator that evaluates to true if the left value is in the right value. Unlike "in", it is case insensitive. If the right value is an array/slice, then evaluated to true if the left value is in the array/slice. Otherwise, evaluates to true if the right string is contained by the left string.

func (IIn) Compile Uses

func (i IIn) Compile() Node

func (IIn) Dfl Uses

func (i IIn) Dfl(quotes []string, pretty bool, tabs int) string

func (IIn) Evaluate Uses

func (i IIn) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (IIn) Map Uses

func (i IIn) Map() map[string]interface{}

func (IIn) Sql Uses

func (i IIn) Sql(pretty bool, tabs int) string

type ILike Uses

type ILike struct {
    *BinaryOperator
}

func (ILike) Compile Uses

func (i ILike) Compile() Node

func (ILike) Dfl Uses

func (i ILike) Dfl(quotes []string, pretty bool, tabs int) string

func (ILike) Evaluate Uses

func (i ILike) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (ILike) Map Uses

func (i ILike) Map() map[string]interface{}

func (ILike) Sql Uses

func (i ILike) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type In Uses

type In struct {
    *BinaryOperator
}

In is a BinaryOperator that evaluates to true if the left value is in the right value. The left value is cast as a string using "fmt.Sprint(lv)". If the right value is an array/slice, then evaluated to true if the left value is in the array/slice. Otherwise, evaluates to true if the right string is contained by the left string.

func (In) Compile Uses

func (i In) Compile() Node

func (In) Dfl Uses

func (i In) Dfl(quotes []string, pretty bool, tabs int) string

func (In) Evaluate Uses

func (i In) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (In) Map Uses

func (i In) Map() map[string]interface{}

func (In) Sql Uses

func (i In) Sql(pretty bool, tabs int) string

type Lengther Uses

type Lengther interface {
    Len() int
}

type LessThan Uses

type LessThan struct {
    *NumericBinaryOperator
}

LessThan is a NumericBinaryOperator that evaluating to true if parameter a is less than parameter b. The parameters may be of type int, int64, or float64.

func (LessThan) Compile Uses

func (lt LessThan) Compile() Node

func (LessThan) Dfl Uses

func (lt LessThan) Dfl(quotes []string, pretty bool, tabs int) string

Sql returns the DFL representation of this node as a string

func (LessThan) Evaluate Uses

func (lt LessThan) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (LessThan) Map Uses

func (lt LessThan) Map() map[string]interface{}

func (LessThan) Sql Uses

func (lt LessThan) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type LessThanOrEqual Uses

type LessThanOrEqual struct {
    *NumericBinaryOperator
}

LessThanOrEqual is a NumericBinaryOperator that evaluating to true if parameter a is less than or equal to parameter b. The parameters may be of type int, int64, or float64.

func (LessThanOrEqual) Compile Uses

func (lte LessThanOrEqual) Compile() Node

func (LessThanOrEqual) Dfl Uses

func (lte LessThanOrEqual) Dfl(quotes []string, pretty bool, tabs int) string

Sql returns the DFL representation of this node as a string

func (LessThanOrEqual) Evaluate Uses

func (lte LessThanOrEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (LessThanOrEqual) Map Uses

func (lte LessThanOrEqual) Map() map[string]interface{}

func (LessThanOrEqual) Sql Uses

func (lte LessThanOrEqual) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Like Uses

type Like struct {
    *BinaryOperator
}

Like is a BinaryOperator that evaluates the SQL standard like expression. It is similar to the ILike BinaryOperator but is case sensitive. The parameters must be of type string. The right parameter may have "%" characters that are interpreted as (.*) in a regular expression test.

func (Like) Compile Uses

func (l Like) Compile() Node

func (Like) Dfl Uses

func (l Like) Dfl(quotes []string, pretty bool, tabs int) string

func (Like) Evaluate Uses

func (l Like) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Like) Map Uses

func (l Like) Map() map[string]interface{}

func (Like) Sql Uses

func (l Like) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Literal Uses

type Literal struct {
    Value interface{} // the field containing the actual value
}

Literal is a Node representing a literal/static value regardless of the context. The value may be of any type; however, it will likely a bool, int, or string. For example

Literal{Value: ""}
Literal{Value: 0.0}

func (Literal) Attributes Uses

func (l Literal) Attributes() []string

func (Literal) Compile Uses

func (l Literal) Compile() Node

func (Literal) Dfl Uses

func (l Literal) Dfl(quotes []string, pretty bool, tabs int) string

func (Literal) Evaluate Uses

func (l Literal) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Literal) Map Uses

func (l Literal) Map() map[string]interface{}

func (Literal) Sql Uses

func (l Literal) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

func (Literal) Variables Uses

func (l Literal) Variables() []string

type MultiOperator Uses

type MultiOperator struct {
    Arguments []Node `json:"arguments" bson:"arguments" yaml:"arguments" hcl:"arguments"` // list of function arguments
}

MultiOperator represents an operator with a dynamic list of arguments.

func (MultiOperator) Attributes Uses

func (mo MultiOperator) Attributes() []string

func (MultiOperator) First Uses

func (mo MultiOperator) First() Node

First returns the last argument for this operator, if exists.

func (MultiOperator) Last Uses

func (mo MultiOperator) Last() Node

Last returns the last argument for this operator, if exists.

func (MultiOperator) Map Uses

func (mo MultiOperator) Map(operator string) map[string]interface{}

func (MultiOperator) Variables Uses

func (mo MultiOperator) Variables() []string

type Multiply Uses

type Multiply struct {
    *NumericBinaryOperator
}

Multiply is a NumericBinaryOperator that represents the mathematical multiplication of two nodes.

func (Multiply) Compile Uses

func (m Multiply) Compile() Node

Compile returns a compiled version of this node.

func (Multiply) Dfl Uses

func (m Multiply) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL representation of this node as a string

func (Multiply) Evaluate Uses

func (m Multiply) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

Evaluate evaluates this node given the variables "vars" and context "ctx" and returns the output, and an error if any.

func (Multiply) Map Uses

func (m Multiply) Map() map[string]interface{}

Map returns a map representation of this node.

func (Multiply) Sql Uses

func (m Multiply) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Node Uses

type Node interface {
    Dfl(quotes []string, pretty bool, tabs int) string                                                                                      // returns the DFL expression representation of this node
    Sql(pretty bool, tabs int) string                                                                                                       // returns the SQL representation of this node
    Map() map[string]interface{}                                                                                                            // returns a map representing this node
    Compile() Node                                                                                                                          // compiles this node (and all children).
    Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error) // evaluates the value of a node given a context
    Attributes() []string                                                                                                                   // returns a slice of all attributes used by this node (and all children nodes)
    Variables() []string                                                                                                                    // returns a slice of all variables used by this node (and all children nodes)
}

Node is the interface for representing the constructs of the Dyanmic Filter Language in an Abstract Syntax Tree. This interface is inherited by most structs in the dfl package.

func MustParseCompile Uses

func MustParseCompile(expression string) Node

MustParseCompile parses the input expression and compiles the DFL node. Panics if any error.

func Parse Uses

func Parse(in string) (Node, string, error)

Parse parses a DFL expression into an an Abstract Synatax Tree (AST). Parse returns the AST, remainder, and error if any.

func ParseArray Uses

func ParseArray(in string, remainder string) (Node, string, error)

ParseArray parses an array of nodes. If parameter "in" is gramatically a child node, then return the parent node. DFL arrays can include Attribute or Literal Nodes. As all attribute references must start with an "@" character, parantheses are optional for literals except if a comma exists. Below are some example inputs

[bank, bureau_de_change, atm]
[1, 2, @target]
[Taco, Tacos, Burrito, Burritos, "Mexican Food", @example]

func ParseAttribute Uses

func ParseAttribute(in string, remainder string) (Node, string, error)

ParseAttribute parses an Attribute Node from an input string If parameter "in" is gramatically a child node, then return the parent node. All attribute references must start with an "@" character and have no spaces. For example, @amenity, @shop, @population, etc. Given those rules the remainder, if any, if simply parsed from the input strings Examples:

node, err := ParseAttribute("@amenity in [bar, restaurant]")

func ParseCompile Uses

func ParseCompile(expression string) (Node, error)

ParseCompile parses the input expression and compiles the DFL node.

func ParseFunction Uses

func ParseFunction(in string, remainder string) (Node, string, error)

ParseFunction parses a function from in and attaches the remainder.

func ParseList Uses

func ParseList(in string) ([]Node, error)

ParseList parses a list of values.

func ParseListOrKeyValue Uses

func ParseListOrKeyValue(in string) (bool, []Node, map[Node]Node, error)

ParseList parses a list of values.

func ParseLiteral Uses

func ParseLiteral(v interface{}, remainder string) (Node, string, error)

ParseLiteral wraps parameter v in a Literal Node and parses a remainder, if any. ParseLiteral does not additional parsing of parameter v. TryConvertString is used to parse an int, float64, or time from a string representation. If parameter "in" is gramatically a child node, then return the parent node. For example, @amenity, @shop, @population, etc. Given those rules the remainder, if any, if simply parsed from the input strings Examples:

node, err := ParseLiteral("brewery")

func ParseSetOrDictionary Uses

func ParseSetOrDictionary(in string, remainder string) (Node, string, error)

ParseSetOrDictionary parses a Set or Dictionary Node and recursively any remainder. If parameter "in" is gramatically a child node, then return the parent node. DFL sets/dictionaries can include Attribute or Literal Nodes. As all attribute references must start with an "@" character, parentheses are optional for literals except if a comma exists. Below are some example inputs

{bank, bureau_de_change, atm}
{1, 2, @target}
{Taco, Tacos, Burrito, Burritos, "Mexican Food", @example}
{amenity: bank}

func ParseSub Uses

func ParseSub(s string, remainder string) (Node, string, error)

ParseSub is used to parse a sub-expression and the remainder, if any. A sub-expression is usually enclosed by parantheses. The parantheses are removed before being passed to ParseSub. If parameter "in" is gramatically a child node, then return the parent node. For Example with an input string "(@cuisine like mexican) or (@name ilike %burrito%)",

node, err : ParseSub("@cuisine like mexican", "or (@name ilike %burrito%)")

func ParseVariable Uses

func ParseVariable(in string, remainder string) (Node, string, error)

ParseVariable parses a Variable Node from an input string If parameter "in" is gramatically a child node, then return the parent node. All variable references must start with an "$" character and have no spaces. For example, $amenity, $shop, $population, etc. Given those rules the remainder, if any, if simply parsed from the input strings Examples:

node, err := ParseAttribute("$amenities := [bar, restaurant]")

type Not Uses

type Not struct {
    *UnaryOperator
}

Not is a UnaryOperator that inverts the boolean value of the children Node.

func (Not) Compile Uses

func (n Not) Compile() Node

Compile returns a compiled version of this node. If the the child Node is compiled as a boolean Literal, then returns an inverse Literal Node. Otherwise returns a clone of this node.

func (Not) Dfl Uses

func (n Not) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL representation of this node (and its children nodes)

func (Not) Evaluate Uses

func (n Not) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

Evaluate evaluates this node within a context and returns the bool result, and error if any.

func (Not) Map Uses

func (n Not) Map() map[string]interface{}

Map returns a map representation of this node (and its children nodes)

func (Not) Sql Uses

func (n Not) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type NotEqual Uses

type NotEqual struct {
    *BinaryOperator
}

NotEqual is a BinaryOperator that evaluates to true if the left value is not equal to the right value. The values may be of type int, int64, or float64.

func (NotEqual) Compile Uses

func (ne NotEqual) Compile() Node

func (NotEqual) Dfl Uses

func (ne NotEqual) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL expression representation of the node as a string value. For example

"( @amenity  !=  shop )"

func (NotEqual) Evaluate Uses

func (ne NotEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (NotEqual) Map Uses

func (ne NotEqual) Map() map[string]interface{}

func (NotEqual) Sql Uses

func (ne NotEqual) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Null Uses

type Null struct{}

Null is used as return value for Extract and DFL functions instead of returning nil pointers.

func (Null) Dfl Uses

func (n Null) Dfl() string

func (Null) Sql Uses

func (n Null) Sql() string

type NumericBinaryOperator Uses

type NumericBinaryOperator struct {
    *BinaryOperator // Extends the BinaryOperator struct
}

NumericBinaryOperator is an abstract struct extending the BinaryOperator struct. NumericBinaryOperator is a convience struct that attaches to EvaluateAndCompare function that is used by structs implementing the Node interface.

func (NumericBinaryOperator) EvaluateAndCompare Uses

func (nbo NumericBinaryOperator) EvaluateAndCompare(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, int, error)

EvaluateAndCompare returns the value of the node given the Context ctx, and error if any. If the left value and right value are mathematically equal, returns 0. If the left value is less than the right value, returns -1. if the left value is greater than the right value, returns 1.

type Or Uses

type Or struct {
    *BinaryOperator
}

Or is a BinaryOperator which represents the logical boolean OR operation of left and right values.

func (Or) Compile Uses

func (o Or) Compile() Node

Compile returns a compiled version of this node. If the left value and right value are both compiled as Literals, then returns the logical boolean AND operation of the left and right value. Otherwise, returns a clone.

func (Or) Dfl Uses

func (o Or) Dfl(quotes []string, pretty bool, tabs int) string

func (Or) Evaluate Uses

func (o Or) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Or) Map Uses

func (o Or) Map() map[string]interface{}

func (Or) Sql Uses

func (o Or) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Pipe Uses

type Pipe struct {
    *BinaryOperator
}

Pipe is a BinaryOperator which represents the "|" pipe operation of left and right values.

func (Pipe) Compile Uses

func (p Pipe) Compile() Node

Compile returns a compiled version of this node. If the left value and right value are both compiled as Literals, then returns the logical boolean AND operation of the left and right value. Otherwise, returns a clone.

func (Pipe) Dfl Uses

func (p Pipe) Dfl(quotes []string, pretty bool, tabs int) string

func (Pipe) Evaluate Uses

func (p Pipe) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Pipe) Last Uses

func (p Pipe) Last() Node

func (Pipe) Map Uses

func (p Pipe) Map() map[string]interface{}

func (Pipe) Sql Uses

func (p Pipe) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Pipeline Uses

type Pipeline struct {
    Nodes []Node
}

Pipeline is a Node representing a pipeline of nodes where the output of each node is used as the input for the next.

func (Pipeline) Attributes Uses

func (p Pipeline) Attributes() []string

func (Pipeline) Compile Uses

func (p Pipeline) Compile() Node

Compile returns a compiled version of this node. If all the values of an Set are literals, returns a single Literal with the corresponding array as its value. Otherwise returns the original node..

func (Pipeline) Dfl Uses

func (p Pipeline) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL representation of this node as a string

func (Pipeline) Evaluate Uses

func (p Pipeline) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Pipeline) Len Uses

func (p Pipeline) Len() int

Len returns the length of the underlying array.

func (Pipeline) Map Uses

func (p Pipeline) Map() map[string]interface{}

func (Pipeline) Sql Uses

func (p Pipeline) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

func (Pipeline) Variables Uses

func (p Pipeline) Variables() []string

type Print Uses

type Print struct {
    *UnaryOperator
}

Print is a UnaryOperator that prints a value to stdout

func (Print) Compile Uses

func (p Print) Compile() Node

Compile returns a compiled version of this node. If the the child Node is compiled as a boolean Literal, then returns an inverse Literal Node. Otherwise returns a clone of this node.

func (Print) Dfl Uses

func (p Print) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL representation of this node (and its children nodes)

func (Print) Evaluate Uses

func (p Print) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

Evaluate evaluates this node within a context and returns the bool result, and error if any.

func (Print) Map Uses

func (p Print) Map() map[string]interface{}

Map returns a map representation of this node (and its children nodes)

func (Print) Sql Uses

func (p Print) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Reader Uses

type Reader interface {
    ReadAll() ([]byte, error)
    ReadRange(start int, end int) ([]byte, error)
}

type Set Uses

type Set struct {
    Nodes []Node
}

Set is a Node representing a set of values, which can be either a Literal or Attribute.

func (Set) Attributes Uses

func (a Set) Attributes() []string

func (Set) Compile Uses

func (a Set) Compile() Node

Compile returns a compiled version of this node. If all the values of an Set are literals, returns a single Literal with the corresponding Set/slice as its value. Otherwise returns the original node..

func (Set) Dfl Uses

func (s Set) Dfl(quotes []string, pretty bool, tabs int) string

func (Set) Evaluate Uses

func (a Set) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Set) Len Uses

func (s Set) Len() int

Len returns the length of the underlying array.

func (Set) Map Uses

func (a Set) Map() map[string]interface{}

func (Set) Sql Uses

func (s Set) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

func (Set) Variables Uses

func (a Set) Variables() []string

type StringSet Uses

type StringSet map[string]struct{}

StringSet is a logical set of string values using a map[string]struct{} backend. The use of a string -> empty struct backend provides a higher write performance versus a slice backend.

func NewStringSet Uses

func NewStringSet() StringSet

NewStringSet returns a new StringSet.

func (StringSet) Add Uses

func (set StringSet) Add(values ...string)

Add is a variadic function to add values to a set

- https://gobyexample.com/variadic-functions

func (StringSet) Contains Uses

func (set StringSet) Contains(x string) bool

func (StringSet) Dfl Uses

func (set StringSet) Dfl(quotes []string, pretty bool, tabs int) string

func (StringSet) Intersection Uses

func (set StringSet) Intersection(values interface{}) StringSet

func (StringSet) Intersects Uses

func (set StringSet) Intersects(values interface{}) bool

func (StringSet) Len Uses

func (set StringSet) Len() int

func (StringSet) Slice Uses

func (set StringSet) Slice(sorted bool) sort.StringSlice

Slice returns a slice representation of this set. If parameter sorted is true, then sorts the values using natural sort order.

func (StringSet) Union Uses

func (set StringSet) Union(values interface{}) StringSet

type Subtract Uses

type Subtract struct {
    *NumericBinaryOperator
}

func (Subtract) Compile Uses

func (s Subtract) Compile() Node

func (Subtract) Dfl Uses

func (s Subtract) Dfl(quotes []string, pretty bool, tabs int) string

func (Subtract) Evaluate Uses

func (s Subtract) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Subtract) Map Uses

func (s Subtract) Map() map[string]interface{}

func (Subtract) Sql Uses

func (s Subtract) Sql(pretty bool, tabs int) string

type TemporalBinaryOperator Uses

type TemporalBinaryOperator struct {
    *BinaryOperator // Extends the BinaryOperator struct
}

TemporalBinaryOperator is an abstract struct NumericBinaryOperator is a convience struct that attaches to EvaluateAndCompare function that is used by structs implementing the Node interface.

func (TemporalBinaryOperator) EvaluateAndCompare Uses

func (tbo TemporalBinaryOperator) EvaluateAndCompare(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, int, error)

EvaluateAndCompare returns the value of the node given the Context ctx, and error if any. If the left value and right value are at the same time, returns 0. If the left value is before the right value, returns -1. if the left value is after the right value, returns 1.

type TernaryOperator Uses

type TernaryOperator struct {
    Left  Node
    True  Node
    False Node
}

TernaryOperator is a DFL Node that represents the ternary operator of a condition, true value, and false value.

func (TernaryOperator) Attributes Uses

func (to TernaryOperator) Attributes() []string

Attributes returns a slice of all attributes used in the evaluation of this node, including a children nodes. Attributes de-duplicates values from the condition, true, and false nodes using a set.

func (TernaryOperator) Compile Uses

func (to TernaryOperator) Compile() Node

func (TernaryOperator) Dfl Uses

func (to TernaryOperator) Dfl(quotes []string, pretty bool, tabs int) string

func (TernaryOperator) Evaluate Uses

func (to TernaryOperator) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (TernaryOperator) Map Uses

func (to TernaryOperator) Map() map[string]interface{}

func (TernaryOperator) Sql Uses

func (to TernaryOperator) Sql(pretty bool, tabs int) string

func (TernaryOperator) Variables Uses

func (to TernaryOperator) Variables() []string

Variables returns a slice of all variables used in the evaluation of this node, including a children nodes. Variables de-duplicates values from the condition, true, and false nodes using a set.

type TestCase Uses

type TestCase struct {
    Expression string      // the DFL expression
    Context    interface{} // the Context to use for evaluation
    Result     interface{} // The result of the evaluation
}

TestCase is a struct containing the variables for a unit test of expression evaluation.

func NewTestCase Uses

func NewTestCase(exp string, ctx interface{}, result interface{}) TestCase

NewTestCase returns a new TestCase

type UnaryOperator Uses

type UnaryOperator struct {
    Node Node
}

UnaryOperator is an abstract Node the represents an operator with only 1 operand. THe only implementing struct is the "Not" struct.

func (UnaryOperator) Attributes Uses

func (uo UnaryOperator) Attributes() []string

Attributes returns the context attributes used by the child node, if any.

func (UnaryOperator) Variables Uses

func (uo UnaryOperator) Variables() []string

Variables returns the variables used by the child node, if any.

type Variable Uses

type Variable struct {
    Name string
}

Variable is a Node representing the value of a temporary variable. Variables start with a "#" and follow with the name or full path into the object if multiple levels deep. For example, #a and #a.b.c.d. You can also use a null-safe operator, e.g., #a?.b?.c?.d

func (Variable) Attributes Uses

func (v Variable) Attributes() []string

func (Variable) Compile Uses

func (v Variable) Compile() Node

func (Variable) Dfl Uses

func (v Variable) Dfl(quotes []string, pretty bool, tabs int) string

func (Variable) Evaluate Uses

func (v Variable) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Variable) Map Uses

func (v Variable) Map() map[string]interface{}

func (Variable) Sql Uses

func (v Variable) Sql(pretty bool, tabs int) string

func (Variable) Variables Uses

func (v Variable) Variables() []string

type Within Uses

type Within struct {
    *BinaryOperator
}

Within is a BinaryOperator that represents that the left value is between

func (Within) Compile Uses

func (w Within) Compile() Node

Compile returns a compiled version of this node. If the left and right values are both compiled as literals, then returns the compiled Literal with that value set. Otherwise returns a clone of this node.

func (Within) Dfl Uses

func (w Within) Dfl(quotes []string, pretty bool, tabs int) string

Dfl returns the DFL representation of this node as a string

func (Within) Evaluate Uses

func (w Within) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

Evaluate returns the value of this node given Context ctx, and an error if any.

func (Within) Map Uses

func (w Within) Map() map[string]interface{}

Map returns a map representation of this node

func (Within) Sql Uses

func (w Within) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string

type Xor Uses

type Xor struct {
    *BinaryOperator // Extends the BinaryOperator struct
}

Xor is a BinaryOperator which represents the logical boolean XOR operation of left and right values.

- https://en.wikipedia.org/wiki/Exclusive_or

func (Xor) Compile Uses

func (x Xor) Compile() Node

Compile returns a compiled version of this node. If the left value and right value are both compiled as Literals, then returns the logical boolean XOR operation of the left and right value. Otherwise, returns a clone.

func (Xor) Dfl Uses

func (x Xor) Dfl(quotes []string, pretty bool, tabs int) string

func (Xor) Evaluate Uses

func (x Xor) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error)

func (Xor) Map Uses

func (x Xor) Map() map[string]interface{}

func (Xor) Sql Uses

func (x Xor) Sql(pretty bool, tabs int) string

Sql returns the SQL representation of this node as a string Equivalent to (A and not B) or (not A and B)

Directories

PathSynopsis
builderPackage builder is for building DFL expressions.
cache
request
syntaxPackage syntax includes functions for parsing syntax.

Package dfl imports 21 packages (graph) and is imported by 6 packages. Updated 2019-05-07. Refresh now. Tools for package owners.