Skip to main content

Module expr

Module expr 

Source
Expand description

Typed expression AST (Django Q / F / lookup equivalents).

Expressions are pure data: building them never performs I/O. Backends compile them into their own dialect.

Two layers exist:

  • Expr: untyped tree stored inside a QueryPlan.
  • Field<M, T>: a typed column handle. The Model derive generates one associated constant per field (User::name), so lookups are checked at compile time: icontains exists only on text fields, comparison values must convert into the field’s type. Calc (arithmetic results) and Joined (fields reached through a foreign key) offer the same lookups.

Function, aggregate and window constructors live in functions, Count/Sum/… and RowNumber/Rank/….

Re-exports§

pub use functions::CaseBuilder;
pub use functions::DatePart;
pub use functions::Function;

Modules§

functions
Scalar functions, CASE and date-part extraction.

Structs§

Aggregate
An aggregate call: function, argument, DISTINCT and FILTER (WHERE ..).
ArrayAgg
Collect values into an array (PostgreSQL only).
Avg
AVG(expr).
Calc
Result of arithmetic on typed handles: an expression that is still known to have type T, so it can be compared with and assigned to T fields.
Column
A (optionally source-qualified) column reference.
Count
COUNT(*) and COUNT(expr).
CumeDist
CUME_DIST().
DenseRank
DENSE_RANK().
Field
Typed column handle for model M whose Rust type is T.
FirstValue
FIRST_VALUE(expr).
Joined
A column of a related model, usable like a field of the root model M.
Lag
LAG(expr, offset).
LastValue
LAST_VALUE(expr).
Lead
LEAD(expr, offset).
Max
MAX(expr).
Min
MIN(expr).
Ntile
NTILE(n).
PercentRank
PERCENT_RANK().
Rank
RANK().
RelHop
One foreign-key hop: <parent>.<fk_column> = <table>.<pk_column>.
RelatedColumn
A column of a related model, addressed by its foreign-key path.
RowNumber
ROW_NUMBER().
StdDev
Standard deviation (PostgreSQL only).
StringAgg
Join text values with a separator (STRING_AGG on PostgreSQL, group_concat on SQLite).
Sum
SUM(expr). NULL for an empty group; PostgreSQL returns numeric for integer sums.
Variance
Variance (PostgreSQL only).
Window
A window function with its PARTITION BY and ORDER BY.

Enums§

AggFunc
The aggregate function computed.
BinaryOp
Binary operators: comparisons, boolean connectives and arithmetic.
Expr
Expression tree node.
Lookup
Lookups that are not plain binary comparisons.
UnaryOp
Unary operators.
WindowFunc
The function evaluated over the window.

Traits§

DateLike
Column types that have a calendar date (year, month, …).
FkSlot
A foreign-key slot of a model struct: ForeignKey<T> or Option<ForeignKey<T>>.
Literal
A literal value that can stand for a T column (no column references), used by is_in and range.
Numeric
Column types that support arithmetic.
Operand
A value that can stand for a T column in a comparison or assignment: a T, a T for an Option<T> column, a primary key or model reference for a foreign key, or another typed handle of type T.
Related
Column of related model T that can be reached through more hops: a Field of T, or a Joined handle already rooted at T.
TextLike
Text column types (icontains, starts_with, …).
TimeLike
Column types that have a time of day (hour, minute, second).

Functions§

path_alias_of
Alias of the table reached by path.

Type Aliases§

Ident
Identifier type used for tables, aliases and columns.