Documentation ¶
Overview ¶
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 ¶
- Constants
- func Pretty(pretty bool) func(*QueryParser) error
- func Size(size int) func(*QueryParser) error
- type Condition
- type Empty
- type Operator
- type Query
- type QueryParser
- func (t *QueryParser) AST() *node32
- func (t *QueryParser) Add(rule pegRule, begin, end, index uint32)
- func (p *QueryParser) Init(options ...func(*QueryParser) error) error
- func (p *QueryParser) Parse(rule ...int) error
- func (t *QueryParser) PrettyPrintSyntaxTree(buffer string)
- func (t *QueryParser) Print()
- func (p *QueryParser) PrintSyntaxTree()
- func (p *QueryParser) Reset()
- func (p *QueryParser) SprintSyntaxTree() string
- func (t *QueryParser) Tokens() []token32
- func (t *QueryParser) Trim(length uint32)
- func (p *QueryParser) WriteSyntaxTree(w io.Writer)
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 )
Variables ¶
This section is empty.
Functions ¶
func Pretty ¶
func Pretty(pretty bool) func(*QueryParser) error
func Size ¶
func Size(size int) func(*QueryParser) error
Types ¶
type Condition ¶
Condition represents a single condition within a query and consists of composite key (e.g. "tx.gas"), operator (e.g. "=") and operand (e.g. "7").
type Empty ¶
type Empty struct { }
Empty query matches any set of events.
type Operator ¶
type Operator uint8
Operator is an operator that defines some kind of relation between composite key and operand (equality, etc.).
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query holds the query string and the query parser.
func MustParse ¶
MustParse turns the given string into a query or panics; for tests or others cases where you know the string is valid.
func (*Query) Conditions ¶
Conditions returns a list of conditions. It returns an error if there is any error with the provided grammar in the Query.
func (*Query) Matches ¶
Matches returns true if the query matches against any event in the given set of events, false otherwise. For each event, a match exists if the query is matched against *any* value in a slice of values. An error is returned if any attempted event match returns an error.
For example, query "name=John" matches events = {"name": ["John", "Eric"]}. More examples could be found in parser_test.go and query_test.go.
type QueryParser ¶
func (*QueryParser) Init ¶
func (p *QueryParser) Init(options ...func(*QueryParser) error) error
func (*QueryParser) Parse ¶
func (p *QueryParser) Parse(rule ...int) error
func (*QueryParser) PrettyPrintSyntaxTree ¶
func (t *QueryParser) PrettyPrintSyntaxTree(buffer string)
func (*QueryParser) PrintSyntaxTree ¶
func (p *QueryParser) PrintSyntaxTree()
func (*QueryParser) Reset ¶
func (p *QueryParser) Reset()
func (*QueryParser) SprintSyntaxTree ¶
func (p *QueryParser) SprintSyntaxTree() string
func (*QueryParser) WriteSyntaxTree ¶
func (p *QueryParser) WriteSyntaxTree(w io.Writer)