...

Package mango

import "github.com/go-kivik/kivik/v4/x/mango"
Overview
Index

Overview ▾

Package mango provides a Mango query language parser and evaluator.

Constants

Combination Operators

const (
    OpAnd         = Operator("$and")
    OpOr          = Operator("$or")
    OpNot         = Operator("$not")
    OpNor         = Operator("$nor")
    OpAllMatch    = Operator("$allMatch")
    OpKeyMapMatch = Operator("$keyMapMatch")
)

Condition Operators

const (
    OpLessThan           = Operator("$lt")
    OpLessThanOrEqual    = Operator("$lte")
    OpEqual              = Operator("$eq")
    OpNotEqual           = Operator("$ne")
    OpGreaterThan        = Operator("$gt")
    OpGreaterThanOrEqual = Operator("$gte")
    OpExists             = Operator("$exists")
    OpType               = Operator("$type")
    OpIn                 = Operator("$in")
    OpNotIn              = Operator("$nin")
    OpSize               = Operator("$size")
    OpMod                = Operator("$mod")
    OpRegex              = Operator("$regex")
    OpAll                = Operator("$all")
    OpElemMatch          = Operator("$elemMatch")
)

func Match

func Match(sel Node, doc interface{}) bool

Match returns true if the selector matches the input document. doc is expected to be the result of unmarshaling JSON to an empty interface. An invalid document will cause Match to panic.

func SplitKeys

func SplitKeys(field string) []string

SplitKeys splits a field into its component keys. For example, "foo.bar" is split into `["foo", "bar"]`. Escaped dots are not treated as separators, so `"foo\\.bar"` becomes `["foo.bar"]`.

type Node

Node represents a node in the Mango Selector.

type Node interface {
    Op() Operator
    Value() interface{}
    String() string
    Match(interface{}) bool
}

func Parse

func Parse(input []byte) (Node, error)

Parse parses s into a Mango Selector tree.

type Operator

Operator represents a Mango operator.

type Operator string

type Selector

Selector represents a Mango Selector tree.

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

func (*Selector) Match

func (s *Selector) Match(doc interface{}) bool

Match returns true if doc matches the selector.

func (*Selector) UnmarshalJSON

func (s *Selector) UnmarshalJSON(data []byte) error

UnmarshalJSON parses the JSON-encoded data and stores the result in s.