filter

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Position   int
	Comparable *Comparable
	Composite  *Expression
}

type Comparable

type Comparable struct {
	Position int
	Member   *Member
	Function *Function
}

type Error

type Error struct {
	// Position is a 1-based byte offset into the filter.
	Position int
	Message  string
}

Error carries the offset the filter failed at, which a caller reports back to whoever wrote the filter.

func (*Error) Error

func (e *Error) Error() string

type Expression

type Expression struct {
	Position  int
	Sequences []*Sequence
}

Expression is one or more sequences joined by AND, the loosest binding the grammar has.

func ParseExpression

func ParseExpression(filter string) (*Expression, error)

ParseExpression reads a filter through the EBNF AIP-160 links at https://google.aip.dev/assets/misc/ebnf-filtering.txt and returns nil for the empty filter the grammar admits. It accepts every production, so a caller serving a subset rejects the rest against the tree rather than the text.

type Factor

type Factor struct {
	Position int
	Terms    []*Term
}

Factor is one or more terms joined by OR, which binds tighter than both AND and a sequence.

type Filtering

type Filtering[T any] struct {
	// contains filtered or unexported fields
}

Filtering holds the spec MustCompile checked. A value declared without it carries no spec, which Parse panics on rather than matching no column.

func MustCompile

func MustCompile[T any](spec Spec[T]) Filtering[T]

MustCompile returns what a filter is parsed through, and panics on a spec declared wrong, which no request can recover from and every request repeats.

func (Filtering[T]) Parse

func (f Filtering[T]) Parse(filter string) (Predicate, error)

type Function

type Function struct {
	Position int
	Name     []Value
	Args     []*Arg
}

Function applies a dot-qualified name to zero or more arguments.

type FunctionCompiler

type FunctionCompiler func(args []string) (sql string, binds []any, err error)

FunctionCompiler compiles the call a filter writes into the boolean predicate it stands for. Each argument arrives as the text the client wrote, and the compiler validates count and form. The SQL is parenthesised by the caller, so it may carry an OR.

type Member

type Member struct {
	Position int
	Value    Value
	Fields   []Value
}

Member is a value followed by the fields a dot qualifies it with.

type Predicate

type Predicate struct {
	SQL  string
	Args []any
}

Predicate is the SQL a filter compiles to and the arguments it binds. Bind arguments are placed with ?, which a caller on a driver numbering them rebinds. Every chain of more than one part is parenthesised, so a caller joining the predicate with AND binds all of it.

func (Predicate) Empty

func (p Predicate) Empty() bool

Empty reports whether the filter matched every row, which the caller sending none asks for.

type Restriction

type Restriction struct {
	Position   int
	Comparable *Comparable
	Comparator string
	Arg        *Arg
}

Restriction compares a comparable against an argument. Comparator and Arg stay empty where the restriction names a comparable alone, which AIP-160 calls a global restriction.

type Sequence

type Sequence struct {
	Position int
	Factors  []*Factor
}

Sequence is one or more factors joined by whitespace alone.

type Simple

type Simple struct {
	Position    int
	Restriction *Restriction
	Composite   *Expression
}

type Spec

type Spec[T any] struct {
	// Fields maps the name a client writes in filter to the column it matches.
	Fields map[string]queryfield.Field[T]
	// Functions maps the name a client calls in filter to what the call
	// compiles to. A call not named here is refused.
	Functions map[string]FunctionCompiler
	// LeadingWildcard takes a * opening a value, which matches on a suffix and
	// reads every row of the table, since no btree orders a string by its end.
	LeadingWildcard bool
}

type Term

type Term struct {
	Position int
	Negated  bool
	Simple   *Simple
}

Term is a simple expression that a leading NOT or - negates.

type Value

type Value struct {
	Position int
	Quoted   bool
	Text     string
}

Value is one TEXT or STRING token. Quoted separates the two, which decides whether a - or a . the value carries reached the lexer as an operator.

Jump to

Keyboard shortcuts

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