query

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package query defines Ridu's transport-independent query language.

The same query model is shared by access filters, local operations, the HTTP API, generated clients, and storage adapters.

Index

Constants

View Source
const (
	// MaxPathSegments bounds recursive query compilation and schema traversal.
	// Ridu's operation engine supports substantially shallower authored models,
	// leaving this ceiling as a fail-safe rather than a practical restriction.
	MaxPathSegments = 64
	// MaxPathBytes bounds user-supplied filter/sort/population path allocation.
	MaxPathBytes = 4096
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparison

type Comparison struct {
	Path     Path
	Operator Operator
	Value    Value
}

Comparison is a read-only snapshot of a comparison expression.

type Direction

type Direction string

Direction controls one stable sort term.

const (
	Ascending  Direction = "asc"
	Descending Direction = "desc"
)

type Expression

type Expression interface {
	Kind() ExpressionKind
	Node() Node
	// contains filtered or unexported methods
}

Expression is an immutable query expression. Implementations are sealed so every transport and store sees the same finite query language.

func And

func And(expressions ...Expression) (Expression, error)

And combines two or more expressions.

func Compare

func Compare(path Path, operator Operator, value Value) (Expression, error)

Compare constructs a validated field comparison.

func Contains

func Contains(path Path, value string) Expression

func Equal

func Equal(path Path, value Value) Expression

Equal constructs an equality expression.

func GreaterThan

func GreaterThan(path Path, value Value) Expression

func GreaterThanEqual

func GreaterThanEqual(path Path, value Value) Expression

func In

func In(path Path, values ...Value) Expression

In constructs a membership expression.

func LessThan

func LessThan(path Path, value Value) Expression

func LessThanEqual

func LessThanEqual(path Path, value Value) Expression

func Like

func Like(path Path, value string) Expression

func Not

func Not(child Expression) (Expression, error)

Not negates one expression.

func NotEqual

func NotEqual(path Path, value Value) Expression

NotEqual constructs an inequality expression.

func Or

func Or(expressions ...Expression) (Expression, error)

Or combines two or more expressions.

type ExpressionKind

type ExpressionKind string

ExpressionKind identifies the shape of an expression node.

const (
	ExpressionComparison ExpressionKind = "comparison"
	ExpressionAnd        ExpressionKind = "and"
	ExpressionOr         ExpressionKind = "or"
	ExpressionNot        ExpressionKind = "not"
)

type Node

type Node struct {
	Kind       ExpressionKind
	Comparison *Comparison
	Children   []Node
}

Node is a detached recursive snapshot for adapters and protocol encoders. Mutating a Node never mutates the originating Expression.

type Operator

type Operator string

Operator identifies a field comparison.

const (
	OperatorEqual            Operator = "equal"
	OperatorNotEqual         Operator = "not_equal"
	OperatorIn               Operator = "in"
	OperatorExists           Operator = "exists"
	OperatorGreaterThan      Operator = "greater_than"
	OperatorGreaterThanEqual Operator = "greater_than_equal"
	OperatorLessThan         Operator = "less_than"
	OperatorLessThanEqual    Operator = "less_than_equal"
	OperatorContains         Operator = "contains"
	OperatorLike             Operator = "like"
)

type Path

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

Path is an immutable, validated document field path. Its canonical string form joins segments with a dot, for example "seo.title". The exact single-segment paths "_status" and "_revision" address Ridu's finite version metadata; arbitrary underscore-prefixed or nested system paths remain invalid.

func NewPath

func NewPath(segments ...string) (Path, error)

NewPath validates and constructs a field path from individual segments.

func ParsePath

func ParsePath(value string) (Path, error)

ParsePath validates and constructs a path from its dot-separated form.

func (Path) MarshalJSON

func (path Path) MarshalJSON() ([]byte, error)

MarshalJSON encodes a path in its canonical dot-separated form.

func (Path) Segments

func (path Path) Segments() []string

Segments returns a copy of the path segments.

func (Path) String

func (path Path) String() string

func (*Path) UnmarshalJSON

func (path *Path) UnmarshalJSON(encoded []byte) error

UnmarshalJSON validates the canonical string before replacing the path.

type Population

type Population struct {
	Path  Path
	Depth int
	// Select is nil for the complete populated target. A non-nil empty slice
	// returns only document metadata.
	Select []Path
}

Population asks a store to replace one relationship ID with its projected target document. Depth is bounded by the operation engine.

type Sort

type Sort struct {
	Path      Path
	Direction Direction
}

Sort is one validated ordered field term. Stores append ID as a stable tiebreaker when callers do not provide it explicitly.

func NewSort

func NewSort(path Path, direction Direction) (Sort, error)

type Value

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

Value is an immutable query operand. Explicit constructors prevent arbitrary application values from leaking into the public query contract.

func Boolean

func Boolean(value bool) Value

Boolean constructs a boolean operand.

func List

func List(values ...Value) Value

List constructs a copied list operand.

func Null

func Null() Value

Null constructs a null operand.

func Number

func Number(value float64) Value

Number constructs a number operand.

func String

func String(value string) Value

String constructs a string operand.

func (Value) BooleanValue

func (value Value) BooleanValue() (bool, bool)

BooleanValue returns the boolean and true when this is a boolean operand.

func (Value) Kind

func (value Value) Kind() ValueKind

Kind returns the operand's discriminant.

func (Value) MarshalJSON

func (value Value) MarshalJSON() ([]byte, error)

func (Value) NumberValue

func (value Value) NumberValue() (float64, bool)

NumberValue returns the number and true when this is a number operand.

func (Value) StringValue

func (value Value) StringValue() (string, bool)

StringValue returns the string and true when this is a string operand.

func (Value) Values

func (value Value) Values() []Value

Values returns a deep copy for a list operand.

type ValueKind

type ValueKind string

ValueKind identifies the concrete scalar or list represented by a Value.

const (
	ValueString  ValueKind = "string"
	ValueNumber  ValueKind = "number"
	ValueBoolean ValueKind = "boolean"
	ValueNull    ValueKind = "null"
	ValueList    ValueKind = "list"
)

Jump to

Keyboard shortcuts

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