query

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: Apache-2.0 Imports: 8 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
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition struct {
	CompositeKey string
	Op           Operator
	Operand      interface{}
}

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.

func (Empty) Matches

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

Matches always returns true.

func (Empty) String

func (Empty) String() string

type Operator

type Operator uint8

Operator is an operator that defines some kind of relation between composite key 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
	// "EXISTS"; used to check if a certain event attribute is present.
	OpExists
)

type Query

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

Query holds the query string and the query parser.

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 (*Query) Conditions

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

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

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

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.

func (*Query) String

func (q *Query) String() string

String returns the original string.

type QueryParser

type QueryParser struct {
	Buffer string

	Parse  func(rule ...int) error
	Reset  func()
	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, depth uint32, index int)

func (*QueryParser) Error

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

func (*QueryParser) Expand

func (t *QueryParser) Expand(index int)

func (*QueryParser) Highlighter

func (p *QueryParser) Highlighter()

func (*QueryParser) Init

func (p *QueryParser) Init()

func (*QueryParser) Order

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

func (*QueryParser) PreOrder

func (t *QueryParser) PreOrder() (<-chan state32, [][]token32)

func (*QueryParser) Print

func (t *QueryParser) Print()

func (*QueryParser) PrintSyntax

func (t *QueryParser) PrintSyntax()

func (*QueryParser) PrintSyntaxTree

func (p *QueryParser) PrintSyntaxTree()

func (*QueryParser) Tokens

func (t *QueryParser) Tokens() <-chan token32

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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