query

package
v1.6.23 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

README

Query

Control Flow

  • Grouping with ( and )
  • Chaining with and and or
    • NO mixing! Be explicit and use grouping.
  • Negation with not
    • in front of expression for group: not (...)
    • inside expression for clause: name not matches "^King "

Selectors

Supported by all feeders:

  • root level field: field
  • sub level field: field.sub
  • array/slice/map access: map.0
  • array/slice/map length: map.#

Please note that some feeders may have other special characters. It is advised to only use alphanumeric characters for keys.

Operators

Name Textual Req. Type Internal Type Compared with
Equals == int int64 ==
GreaterThan > int int64 >
GreaterThanOrEqual >= int int64 >=
LessThan < int int64 <
LessThanOrEqual <= int int64 <=
FloatEquals f== float float64 ==
FloatGreaterThan f> float float64 >
FloatGreaterThanOrEqual f>= float float64 >=
FloatLessThan f< float float64 <
FloatLessThanOrEqual f<= float float64 <=
SameAs sameas, s== string string ==
Contains contains, co string string strings.Contains()
StartsWith startswith, sw string string strings.HasPrefix()
EndsWith endswith, ew string string strings.HasSuffix()
In in string string for loop with ==
Matches matches, re string string regexp.Regexp.Matches()
Is is bool* bool ==
Exists exists, ex any n/a n/a

*accepts strings: 1, t, T, true, True, TRUE, 0, f, F, false, False, FALSE

Escaping

If you need to use a control character within a value (ie. not for controlling), escape it with \. It is recommended to wrap a word into parenthesis instead of escaping control characters, when possible.

Location Characters to be escaped
Within parenthesis (") ", \
Everywhere else (, ), ", \, \t, \r, \n, (space)

Documentation

Index

Constants

View Source
const (
	Equals                  uint8 = iota // int
	GreaterThan                          // int
	GreaterThanOrEqual                   // int
	LessThan                             // int
	LessThanOrEqual                      // int
	FloatEquals                          // float
	FloatGreaterThan                     // float
	FloatGreaterThanOrEqual              // float
	FloatLessThan                        // float
	FloatLessThanOrEqual                 // float
	SameAs                               // string
	Contains                             // string
	StartsWith                           // string
	EndsWith                             // string
	In                                   // stringSlice
	Matches                              // regex
	Is                                   // bool: accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE
	Exists                               // any

)

Operators.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition interface {
	// contains filtered or unexported methods
}

Condition is an interface to provide a common api to all condition types.

func And

func And(conditions ...Condition) Condition

And combines multiple conditions with a logical _AND_ operator.

func Not

func Not(c Condition) Condition

Not negates the supplied condition.

func Or

func Or(conditions ...Condition) Condition

Or combines multiple conditions with a logical _OR_ operator.

func Where

func Where(key string, operator uint8, value interface{}) Condition

Where returns a condition to add to a query.

type Query

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

Query contains a compiled query.

func New

func New(prefix string) *Query

New creates a new query with the supplied prefix.

func ParseQuery

func ParseQuery(query string) (*Query, error)

ParseQuery parses a plaintext query. Special characters (that must be escaped with a '\') are: `\()` and any whitespaces.

func (*Query) Check

func (q *Query) Check() (*Query, error)

Check checks for errors in the query.

func (*Query) DatabaseKeyPrefix

func (q *Query) DatabaseKeyPrefix() string

DatabaseKeyPrefix returns the key prefix for the database.

func (*Query) DatabaseName

func (q *Query) DatabaseName() string

DatabaseName returns the name of the database.

func (*Query) IsChecked

func (q *Query) IsChecked() bool

IsChecked returns whether they query was checked.

func (*Query) Limit

func (q *Query) Limit(limit int) *Query

Limit limits the number of returned results.

func (*Query) Matches

func (q *Query) Matches(r record.Record) bool

Matches checks whether the query matches the supplied database record.

func (*Query) MatchesAccessor

func (q *Query) MatchesAccessor(acc accessor.Accessor) bool

MatchesAccessor checks whether the query matches the supplied accessor (value only).

func (*Query) MatchesKey

func (q *Query) MatchesKey(dbKey string) bool

MatchesKey checks whether the query matches the supplied database key (key without database prefix).

func (*Query) MatchesRecord

func (q *Query) MatchesRecord(r record.Record) bool

MatchesRecord checks whether the query matches the supplied database record (value only).

func (*Query) MustBeValid

func (q *Query) MustBeValid() *Query

MustBeValid checks for errors in the query and panics if there is an error.

func (*Query) Offset

func (q *Query) Offset(offset int) *Query

Offset sets the query offset.

func (*Query) OrderBy

func (q *Query) OrderBy(key string) *Query

OrderBy orders the results by the given key.

func (*Query) Print

func (q *Query) Print() string

Print returns the string representation of the query.

func (*Query) Where

func (q *Query) Where(condition Condition) *Query

Where adds filtering.

Jump to

Keyboard shortcuts

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