query

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package query parses and checks the list query language (where, order_by) against a collection's schema, producing backend-neutral storage conditions. Client input never reaches the database as-is: only the operators below exist, and every field and value is checked.

Index

Constants

View Source
const (
	MaxWhereBytes    = 4096 // size of the raw where parameter
	MaxConditions    = 32   // operator clauses in where
	MaxTextLen       = 256  // value length for text operators
	MaxLikeWildcards = 4    // % and _ in a $like / $ilike pattern
	MaxSortFields    = 8    // fields in order_by
	MaxGroupDepth    = 4    // nesting of $or / $and groups
)

Limits on query complexity.

Variables

This section is empty.

Functions

func Cursorable added in v0.5.0

func Cursorable(sort []storage.SortField, fields map[string]registry.Field) (ok bool, field string)

Cursorable reports whether a cursor can follow the sort. When it can't, field names the sort field that stops it.

func EncodeCursor added in v0.5.0

func EncodeCursor(sort []storage.SortField, doc storage.Document) string

EncodeCursor makes the cursor that continues after doc in this sort. The sort must be Cursorable.

func ParseCount

func ParseCount(s string) (bool, error)

ParseCount parses the count parameter ("", "true" or "false").

func ParseCursor added in v0.5.0

func ParseCursor(cursor string, sort []storage.SortField, fields map[string]registry.Field) (storage.Filter, error)

ParseCursor checks a cursor against the sort it is used with, and returns the condition that selects the documents after its position. Anything else is reported as an error on the `after` parameter.

func ParseOrderBy

func ParseOrderBy(s string, fields map[string]registry.Field) ([]storage.SortField, error)

ParseOrderBy parses a comma-separated field list with an optional "-" prefix for descending order. An "id" tiebreaker is appended unless id is already present, so pagination is stable. Empty means id ascending.

func ParseWhere

func ParseWhere(where string, fields map[string]registry.Field) (storage.Filter, error)

ParseWhere parses the where parameter (a JSON object) into a filter tree: the object's keys combine with AND, and "$or" / "$and" take an array of where objects. An empty string or object means no filter (nil). Keys are processed in sorted order, so the result is deterministic.

Types

type Error

type Error struct {
	Path   string
	Reason string
}

Error names one problem in a query.

type Errors

type Errors []Error

Errors is returned when a query is invalid; it lists every problem found.

func (Errors) Error

func (e Errors) Error() string

Jump to

Keyboard shortcuts

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