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.
nolint
Index ¶
- Constants
- func AsQueryable(query Query) parsedQuery
- func MapFromTagged(tagged Tagged) map[string]interface{}
- func MustParse(s string) *query
- func New(s string) (*query, error)
- func StringFromValue(value interface{}) string
- 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) AndStrictlyGreaterThan(tag string, operand interface{}) *Builder
- func (qb *Builder) AndStrictlyLessThan(tag string, operand interface{}) *Builder
- func (qb *Builder) Query() (Query, error)
- func (qb *Builder) String() string
- type CombinedTags
- 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()
- 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 (t *QueryParser) Tokens() []token32
- func (t *QueryParser) Trim(length uint32)
- type Queryable
- type ReflectTagged
- 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 MapFromTagged ¶ added in v0.20.0
func MustParse ¶ added in v0.20.0
func MustParse(s string) *query
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 StringFromValue ¶
func StringFromValue(value interface{}) string
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) AndStrictlyGreaterThan ¶
func (*Builder) AndStrictlyLessThan ¶
type CombinedTags ¶ added in v0.20.0
type CombinedTags struct {
// contains filtered or unexported fields
}
func ConcatTags ¶ added in v0.20.0
func ConcatTags(tags ...Tagged) *CombinedTags
func MergeTags ¶ added in v0.20.0
func MergeTags(tags ...Tagged) *CombinedTags
func NewCombinedTags ¶ added in v0.20.0
func NewCombinedTags() *CombinedTags
func (*CombinedTags) AddTags ¶ added in v0.20.0
func (ct *CombinedTags) AddTags(concat bool, tagsList ...Tagged)
Adds each of tagsList to CombinedTags - choosing whether values for the same key should be concatenated or whether the first should value should stick
func (*CombinedTags) Keys ¶ added in v0.20.0
func (ct *CombinedTags) Keys() []string
func (*CombinedTags) Len ¶ added in v0.20.0
func (ct *CombinedTags) Len() (length int)
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.
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 QueryParser ¶ added in v0.20.0
func (*QueryParser) Add ¶ added in v0.20.0
func (t *QueryParser) Add(rule pegRule, begin, end, index uint32)
func (*QueryParser) Init ¶ added in v0.20.0
func (p *QueryParser) Init()
func (*QueryParser) Parse ¶ added in v0.20.0
func (p *QueryParser) Parse(rule ...int) error
func (*QueryParser) PrettyPrintSyntaxTree ¶ added in v0.20.0
func (t *QueryParser) PrettyPrintSyntaxTree(buffer string)
func (*QueryParser) PrintSyntaxTree ¶ added in v0.20.0
func (p *QueryParser) PrintSyntaxTree()
func (*QueryParser) Reset ¶ added in v0.20.0
func (p *QueryParser) Reset()
type Queryable ¶
func MatchAllQueryable ¶
func MatchAllQueryable() Queryable
type ReflectTagged ¶ added in v0.20.0
type ReflectTagged struct {
// contains filtered or unexported fields
}
func MustReflectTags ¶ added in v0.20.0
func MustReflectTags(value interface{}, fieldNames ...string) *ReflectTagged
func ReflectTags ¶ added in v0.20.0
func ReflectTags(value interface{}, fieldNames ...string) (*ReflectTagged, error)
ReflectTags provides a query.Tagged on a structs exported fields using query.StringFromValue to derive the string values associated with each field. If passed explicit field names will only only provide those fields as tags, otherwise all exported fields are provided.
func (*ReflectTagged) Get ¶ added in v0.20.0
func (rt *ReflectTagged) Get(key string) (value string, ok bool)
func (*ReflectTagged) Keys ¶ added in v0.20.0
func (rt *ReflectTagged) Keys() []string
func (*ReflectTagged) Len ¶ added in v0.20.0
func (rt *ReflectTagged) Len() int