burrow: github.com/hyperledger/burrow/event/query Index | Files

package query

import "github.com/hyperledger/burrow/event/query"

Package query provides a parser for a custom query format:

abci.invoice.number=22 AND abci.invoice.owner=Ivan

See query.peg for the grammar, which is a https://en.wikipedia.org/wiki/Parsing_expression_grammar. More: https://github.com/PhilippeSigaud/Pegged/wiki/PEG-Basics

It has a support for numbers (integer and floating point), dates and times.

Index

Package Files

builder.go empty.go expression.go query.go query.peg.go tags.go

Constants

const (
    // DateLayout defines a layout for all dates (`DATE date`)
    DateLayout = "2006-01-02"
    // TimeLayout defines a layout for all times (`TIME time`)
    TimeLayout = time.RFC3339
)
const (
    MultipleValueTagSeparator = ";"
)

func AsQueryable Uses

func AsQueryable(query Query) parsedQuery

func GetReflect Uses

func GetReflect(rv reflect.Value, key string) (interface{}, bool)

func GetReflectDepth Uses

func GetReflectDepth(rv reflect.Value, key string, maxDepth int) (interface{}, bool)

Pull out values in a nested struct by following path

func Pretty Uses

func Pretty(pretty bool) func(*QueryParser) error

func Size Uses

func Size(size int) func(*QueryParser) error

func StringFromValue Uses

func StringFromValue(value interface{}) string

func TaggedPrefix Uses

func TaggedPrefix(prefix string, tagged Tagged) *taggedPrefix

type Builder Uses

type Builder struct {

    // reusable buffer for building queryString
    bytes.Buffer
    // contains filtered or unexported fields
}

A fluent query builder

func NewBuilder Uses

func NewBuilder(queries ...string) *Builder

Creates a new query builder with a base query that is the conjunction of all queries passed

func (*Builder) And Uses

func (qb *Builder) And(queryBuilders ...*Builder) *Builder

Creates the conjunction of Builder and rightQuery

func (*Builder) AndContains Uses

func (qb *Builder) AndContains(tag string, operand interface{}) *Builder

func (*Builder) AndEquals Uses

func (qb *Builder) AndEquals(tag string, operand interface{}) *Builder

Creates the conjunction of Builder and tag = operand

func (*Builder) AndGreaterThanOrEqual Uses

func (qb *Builder) AndGreaterThanOrEqual(tag string, operand interface{}) *Builder

func (*Builder) AndLessThanOrEqual Uses

func (qb *Builder) AndLessThanOrEqual(tag string, operand interface{}) *Builder

func (*Builder) AndStrictlyGreaterThan Uses

func (qb *Builder) AndStrictlyGreaterThan(tag string, operand interface{}) *Builder

func (*Builder) AndStrictlyLessThan Uses

func (qb *Builder) AndStrictlyLessThan(tag string, operand interface{}) *Builder

func (*Builder) Query Uses

func (qb *Builder) Query() (Query, error)

func (*Builder) String Uses

func (qb *Builder) String() string

type CombinedTags Uses

type CombinedTags []interface{}

func TagsFor Uses

func TagsFor(vs ...interface{}) CombinedTags

func (CombinedTags) Get Uses

func (ct CombinedTags) Get(key string) (interface{}, bool)

type Condition Uses

type Condition struct {
    Tag     string
    Op      Operator
    Operand interface{}
}

Condition represents a single condition within a query and consists of tag (e.g. "tx.gas"), operator (e.g. "=") and operand (e.g. "7").

type Empty Uses

type Empty struct {
}

Empty query matches any set of tags.

func (Empty) MatchError Uses

func (empty Empty) MatchError() error

func (Empty) Matches Uses

func (Empty) Matches(tags Tagged) bool

Matches always returns true.

func (Empty) Query Uses

func (Empty) Query() (Query, error)

func (Empty) String Uses

func (Empty) String() string

type Expression Uses

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

A Boolean expression for the query grammar

func (*Expression) Date Uses

func (e *Expression) Date(value string)

func (*Expression) Evaluate Uses

func (e *Expression) Evaluate(getTagValue func(tag string) (interface{}, bool)) (bool, error)

Evaluate expects an Execute() to have filled the code of the Expression so it can be run in the little stack machine below

func (*Expression) Number Uses

func (e *Expression) Number(value string)

func (*Expression) Operator Uses

func (e *Expression) Operator(operator Operator)

func (*Expression) String Uses

func (e *Expression) String() string

func (*Expression) Tag Uses

func (e *Expression) Tag(value string)

func (*Expression) Time Uses

func (e *Expression) Time(value string)

func (*Expression) Value Uses

func (e *Expression) Value(value string)

type MatchError Uses

type MatchError struct {
    Tagged Tagged
    Cause  error
}

func (*MatchError) Error Uses

func (m *MatchError) Error() string

type Operator Uses

type Operator uint8

Operator is an operator that defines some kind of relation between tag and operand (equality, etc.).

const (
    OpTerminal Operator = iota
    OpAnd
    OpOr
    OpLessEqual
    OpGreaterEqual
    OpLess
    OpGreater
    OpEqual
    OpContains
)

func (Operator) String Uses

func (op Operator) String() string

type PegQuery Uses

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

Query holds the query string and the query parser.

func MustParse Uses

func MustParse(s string) *PegQuery

MustParse turns the given string into a query or panics; for tests or others cases where you know the string is valid.

func New Uses

func New(s string) (*PegQuery, error)

New parses the given string and returns a query or error if the string is invalid.

func (*PegQuery) ExplainTo Uses

func (q *PegQuery) ExplainTo(explainer func(fmt string, args ...interface{}))

func (*PegQuery) MatchError Uses

func (q *PegQuery) MatchError() error

Returns whether a matching error occurred (which would result in a false from Matches)

func (*PegQuery) Matches Uses

func (q *PegQuery) Matches(tags Tagged) bool

Matches returns true if the query matches the given set of tags, false otherwise.

For example, query "name=John" matches tags = {"name": "John"}. More examples could be found in parser_test.go and query_test.go.

func (*PegQuery) Query Uses

func (q *PegQuery) Query() (Query, error)

func (*PegQuery) String Uses

func (q *PegQuery) String() string

String returns the original string.

type Query Uses

type Query interface {
    Matches(tags Tagged) bool
    String() string
    MatchError() error
}

func Must Uses

func Must(qry Query, err error) Query

func NewOrEmpty Uses

func NewOrEmpty(queryString string) (Query, error)

type QueryParser Uses

type QueryParser struct {
    Expression

    Buffer string

    Pretty bool
    // contains filtered or unexported fields
}

func (*QueryParser) AST Uses

func (t *QueryParser) AST() *node32

func (*QueryParser) Add Uses

func (t *QueryParser) Add(rule pegRule, begin, end, index uint32)

func (*QueryParser) Execute Uses

func (p *QueryParser) Execute()

func (*QueryParser) Init Uses

func (p *QueryParser) Init(options ...func(*QueryParser) error) error

func (*QueryParser) Parse Uses

func (p *QueryParser) Parse(rule ...int) error

func (*QueryParser) PrettyPrintSyntaxTree Uses

func (t *QueryParser) PrettyPrintSyntaxTree(buffer string)

func (*QueryParser) Print Uses

func (t *QueryParser) Print()

func (*QueryParser) PrintSyntaxTree Uses

func (p *QueryParser) PrintSyntaxTree()

func (*QueryParser) Reset Uses

func (p *QueryParser) Reset()

func (*QueryParser) Tokens Uses

func (t *QueryParser) Tokens() []token32

func (*QueryParser) Trim Uses

func (t *QueryParser) Trim(length uint32)

func (*QueryParser) WriteSyntaxTree Uses

func (p *QueryParser) WriteSyntaxTree(w io.Writer)

type Queryable Uses

type Queryable interface {
    Query() (Query, error)
}

func MatchAllQueryable Uses

func MatchAllQueryable() Queryable

type String Uses

type String string

A yet-to-be-parsed query

func (String) Query Uses

func (qs String) Query() (Query, error)

type TagMap Uses

type TagMap map[string]interface{}

func (TagMap) Get Uses

func (ts TagMap) Get(key string) (value interface{}, ok bool)

type Tagged Uses

type Tagged interface {
    Get(key string) (value interface{}, ok bool)
}

Package query imports 13 packages (graph) and is imported by 38 packages. Updated 2020-05-03. Refresh now. Tools for package owners.