tendermint: github.com/tendermint/tendermint/libs/pubsub/query Index | Files | Directories

package query

import "github.com/tendermint/tendermint/libs/pubsub/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.



Package Files

empty.go query.go query.peg.go


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

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) Matches Uses

func (Empty) Matches(tags map[string][]string) bool

Matches always returns true.

func (Empty) String Uses

func (Empty) String() string

type Operator Uses

type Operator uint8

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

const (
    // "<="
    OpLessEqual Operator = iota
    // ">="
    // "<"
    // ">"
    // "="
    // "CONTAINS"; used to check if a string contains a certain sub string.

type Query Uses

type Query struct {
    // contains filtered or unexported fields

Query holds the query string and the query parser.

func MustParse Uses

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 Uses

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

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

func (*Query) Conditions Uses

func (q *Query) Conditions() []Condition

Conditions returns a list of conditions.

func (*Query) Matches Uses

func (q *Query) Matches(events map[string][]string) bool

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.

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

func (*Query) String Uses

func (q *Query) String() string

String returns the original string.

type QueryParser Uses

type QueryParser struct {
    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) Init Uses

func (p *QueryParser) Init()

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)



Package query imports 7 packages (graph) and is imported by 18 packages. Updated 2019-06-27. Refresh now. Tools for package owners.