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 AsQueryable(query Query) parsedQuery
- func GetReflect(rv reflect.Value, key string) (interface{}, bool)
- func GetReflectDepth(rv reflect.Value, key string, maxDepth int) (interface{}, bool)
- func IsEmpty(query Query) bool
- func StringFromValue(value interface{}) string
- func TaggedPrefix(prefix string, tagged Tagged) *taggedPrefix
- type Builder
- func (qb *Builder) And(queryBuilders ...*Builder) *Builder
- func (qb *Builder) AndContains(tag string, operand interface{}) *Builder
- func (qb *Builder) AndEquals(tag string, operand interface{}) *Builder
- func (qb *Builder) AndGreaterThanOrEqual(tag string, operand interface{}) *Builder
- func (qb *Builder) AndLessThanOrEqual(tag string, operand interface{}) *Builder
- func (qb *Builder) AndNotEquals(tag string, operand interface{}) *Builder
- func (qb *Builder) AndStrictlyGreaterThan(tag string, operand interface{}) *Builder
- func (qb *Builder) AndStrictlyLessThan(tag string, operand interface{}) *Builder
- func (qb *Builder) Not() *Builder
- func (qb *Builder) Or(queryBuilders ...*Builder) *Builder
- func (qb *Builder) Query() (Query, error)
- func (qb *Builder) String() string
- type CombinedTags
- type Condition
- type Empty
- type Expression
- func (e *Expression) Date(value string)
- func (e *Expression) Evaluate(getTagValue func(tag string) (interface{}, bool)) (bool, error)
- func (e *Expression) Number(value string)
- func (e *Expression) Operator(operator Operator)
- func (e *Expression) String() string
- func (e *Expression) Tag(value string)
- func (e *Expression) Time(value string)
- func (e *Expression) Value(value string)
- type MatchError
- type Operator
- type PegQuery
- type Query
- type QueryParser
- func (t *QueryParser) AST() *node32
- func (t *QueryParser) Add(rule pegRule, begin, end, depth uint32, index int)
- func (t *QueryParser) Error() []token32
- func (p *QueryParser) Execute()
- func (t *QueryParser) Expand(index int)
- func (p *QueryParser) Highlighter()
- func (p *QueryParser) Init()
- func (t *QueryParser) Order() [][]token32
- func (t *QueryParser) PreOrder() (<-chan state32, [][]token32)
- func (t *QueryParser) Print()
- func (t *QueryParser) PrintSyntax()
- func (p *QueryParser) PrintSyntaxTree()
- func (t *QueryParser) Tokens() <-chan token32
- type Queryable
- type String
- type TagMap
- type Tagged
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 = ";"
)
Variables ¶
This section is empty.
Functions ¶
func AsQueryable ¶ added in v0.20.0
func AsQueryable(query Query) parsedQuery
func GetReflect ¶ added in v0.28.0
func GetReflectDepth ¶ added in v0.28.0
Pull out values in a nested struct by following path
func StringFromValue ¶
func StringFromValue(value interface{}) string
func TaggedPrefix ¶ added in v0.28.0
Types ¶
type Builder ¶
type Builder struct { // reusable buffer for building queryString bytes.Buffer // contains filtered or unexported fields }
A fluent query builder
func NewBuilder ¶
Creates a new query builder with a base query that is the conjunction of all queries passed
func (*Builder) AndContains ¶
func (*Builder) AndGreaterThanOrEqual ¶
func (*Builder) AndLessThanOrEqual ¶
func (*Builder) AndNotEquals ¶ added in v0.31.0
func (*Builder) AndStrictlyGreaterThan ¶
func (*Builder) AndStrictlyLessThan ¶
type CombinedTags ¶ added in v0.20.0
type CombinedTags []interface{}
func TagsFor ¶ added in v0.28.0
func TagsFor(vs ...interface{}) CombinedTags
func (CombinedTags) Get ¶ added in v0.20.0
func (ct CombinedTags) Get(key string) (interface{}, bool)
type Condition ¶ added in v0.20.0
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 ¶
type Empty struct { }
Empty query matches any set of tags.
func (Empty) MatchError ¶ added in v0.28.0
type Expression ¶ added in v0.28.0
type Expression struct {
// contains filtered or unexported fields
}
A Boolean expression for the query grammar
func (*Expression) Date ¶ added in v0.28.0
func (e *Expression) Date(value string)
func (*Expression) Evaluate ¶ added in v0.28.0
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 ¶ added in v0.28.0
func (e *Expression) Number(value string)
func (*Expression) Operator ¶ added in v0.28.0
func (e *Expression) Operator(operator Operator)
func (*Expression) String ¶ added in v0.28.0
func (e *Expression) String() string
func (*Expression) Tag ¶ added in v0.28.0
func (e *Expression) Tag(value string)
func (*Expression) Time ¶ added in v0.28.0
func (e *Expression) Time(value string)
func (*Expression) Value ¶ added in v0.28.0
func (e *Expression) Value(value string)
type MatchError ¶ added in v0.28.0
func (*MatchError) Error ¶ added in v0.28.0
func (m *MatchError) Error() string
type Operator ¶ added in v0.20.0
type Operator uint8
Operator is an operator that defines some kind of relation between tag and operand (equality, etc.).
type PegQuery ¶ added in v0.28.0
type PegQuery struct {
// contains filtered or unexported fields
}
Query holds the query string and the query parser.
func MustParse ¶ added in v0.20.0
MustParse turns the given string into a query or panics; for tests or others cases where you know the string is valid.
func New ¶ added in v0.20.0
New parses the given string and returns a query or error if the string is invalid.
func (*PegQuery) MatchError ¶ added in v0.28.0
Returns whether a matching error occurred (which would result in a false from Matches)
type Query ¶
func NewOrEmpty ¶ added in v0.24.0
type QueryParser ¶ added in v0.20.0
type QueryParser struct { Expression Buffer string Parse func(rule ...int) error Reset func() Pretty bool // contains filtered or unexported fields }
func (*QueryParser) Execute ¶ added in v0.28.0
func (p *QueryParser) Execute()
func (*QueryParser) Highlighter ¶ added in v0.31.0
func (p *QueryParser) Highlighter()
func (*QueryParser) Init ¶ added in v0.20.0
func (p *QueryParser) Init()
func (*QueryParser) PreOrder ¶ added in v0.31.0
func (t *QueryParser) PreOrder() (<-chan state32, [][]token32)
func (*QueryParser) PrintSyntax ¶ added in v0.31.0
func (t *QueryParser) PrintSyntax()
func (*QueryParser) PrintSyntaxTree ¶ added in v0.20.0
func (p *QueryParser) PrintSyntaxTree()
type Queryable ¶
func MatchAllQueryable ¶
func MatchAllQueryable() Queryable