query

package
v0.0.0-...-24d451d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

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

View Source
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
)
View Source
const (
	MultipleValueTagSeparator = ";"
)

Variables

This section is empty.

Functions

func AsQueryable

func AsQueryable(query Query) parsedQuery

func MapFromTagged

func MapFromTagged(tagged Tagged) map[string]interface{}

func MustParse

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

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

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

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

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

Creates the conjunction of Builder and rightQuery

func (*Builder) AndContains

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

func (*Builder) AndEquals

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

Creates the conjunction of Builder and tag = operand

func (*Builder) AndGreaterThanOrEqual

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

func (*Builder) AndLessThanOrEqual

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

func (*Builder) AndStrictlyGreaterThan

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

func (*Builder) AndStrictlyLessThan

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

func (*Builder) Query

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

func (*Builder) String

func (qb *Builder) String() string

type CombinedTags

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

func ConcatTags

func ConcatTags(tags ...Tagged) *CombinedTags

func MergeTags

func MergeTags(tags ...Tagged) *CombinedTags

func NewCombinedTags

func NewCombinedTags() *CombinedTags

func (*CombinedTags) AddTags

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) Get

func (ct *CombinedTags) Get(key string) (string, bool)

func (*CombinedTags) Keys

func (ct *CombinedTags) Keys() []string

func (*CombinedTags) Len

func (ct *CombinedTags) Len() (length int)

type Condition

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

type Empty struct {
}

Empty query matches any set of tags.

func (Empty) Matches

func (Empty) Matches(tags Tagged) bool

Matches always returns true.

func (Empty) Query

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

func (Empty) String

func (Empty) String() string

type Operator

type Operator uint8

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

const (
	// "<="
	OpLessEqual Operator = iota
	// ">="
	OpGreaterEqual
	// "<"
	OpLess
	// ">"
	OpGreater
	// "="
	OpEqual
	// "CONTAINS"; used to check if a string contains a certain sub string.
	OpContains
)

type Query

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

func Must

func Must(qry Query, err error) Query

func NewOrEmpty

func NewOrEmpty(queryString string) (Query, error)

type QueryParser

type QueryParser struct {
	Buffer string

	Pretty bool
	// contains filtered or unexported fields
}

func (*QueryParser) AST

func (t *QueryParser) AST() *node32

func (*QueryParser) Add

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

func (*QueryParser) Init

func (p *QueryParser) Init()

func (*QueryParser) Parse

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

func (*QueryParser) PrettyPrintSyntaxTree

func (t *QueryParser) PrettyPrintSyntaxTree(buffer string)

func (*QueryParser) Print

func (t *QueryParser) Print()

func (*QueryParser) PrintSyntaxTree

func (p *QueryParser) PrintSyntaxTree()

func (*QueryParser) Reset

func (p *QueryParser) Reset()

func (*QueryParser) Tokens

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

func (*QueryParser) Trim

func (t *QueryParser) Trim(length uint32)

type Queryable

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

func MatchAllQueryable

func MatchAllQueryable() Queryable

type ReflectTagged

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

func MustReflectTags

func MustReflectTags(value interface{}, fieldNames ...string) *ReflectTagged

func ReflectTags

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

func (rt *ReflectTagged) Get(key string) (value string, ok bool)

func (*ReflectTagged) Keys

func (rt *ReflectTagged) Keys() []string

func (*ReflectTagged) Len

func (rt *ReflectTagged) Len() int

type String

type String string

A yet-to-parsed query

func (String) Query

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

type TagMap

type TagMap map[string]interface{}

func (TagMap) Get

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

func (TagMap) Keys

func (ts TagMap) Keys() []string

func (TagMap) Len

func (ts TagMap) Len() int

func (TagMap) Map

func (ts TagMap) Map() map[string]interface{}

type Tagged

type Tagged interface {
	Keys() []string
	Get(key string) (value string, ok bool)
	// Len returns the number of tags.
	Len() int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL