pub enum Expr {
Show 17 variants
Column(String),
CompositeField {
table: String,
column: String,
field: String,
json_key: String,
json_cast: JsonPathCast,
},
Param(Value),
Binary {
left: Box<Expr>,
op: BinaryOp,
right: Box<Expr>,
},
Not(Box<Expr>),
FunctionCall {
name: String,
args: Vec<Expr>,
},
Filter {
expr: Box<Expr>,
predicate: Box<Expr>,
},
Exists(Box<Select>),
NotExists(Box<Select>),
Relation {
op: RelationFilterOp,
relation: Box<RelationFilter>,
},
ScalarSubquery(Box<Select>),
IsNull(Box<Expr>),
IsNotNull(Box<Expr>),
Literal(LiteralSql),
List(Vec<Expr>),
CaseWhen {
condition: Box<Expr>,
then: Box<Expr>,
},
Star,
}Expand description
Expression node for WHERE clauses and filters.
Variants§
Column(String)
Column reference.
CompositeField
Field inside a composite value.
Rendered as a native composite attribute on PostgreSQL and as JSON-path extraction on JSON-backed providers.
Fields
json_cast: JsonPathCastOptional cast hint for JSON-backed providers.
Param(Value)
Parameter placeholder.
Binary
Binary operation.
Not(Box<Expr>)
Logical NOT.
FunctionCall
Function call (e.g., json_agg, COALESCE).
Filter
SQL FILTER clause for aggregate functions (PostgreSQL).
Exists(Box<Select>)
EXISTS subquery predicate — compiles to EXISTS (SELECT ...).
NotExists(Box<Select>)
NOT EXISTS subquery predicate — compiles to NOT EXISTS (SELECT ...).
Relation
Relation predicate (some / none / every) with explicit relation metadata.
Fields
op: RelationFilterOpWhich relation operator to apply.
relation: Box<RelationFilter>Relation metadata and nested child filter.
ScalarSubquery(Box<Select>)
Scalar subquery — compiles to (SELECT ...).
The inner SELECT must return exactly one row and one column. Used for correlated aggregate sub‑queries (e.g. relation includes) that must not produce a cartesian product when two or more relations are joined.
IsNull(Box<Expr>)
IS NULL check — compiles to expr IS NULL.
IsNotNull(Box<Expr>)
IS NOT NULL check — compiles to expr IS NOT NULL.
Literal(LiteralSql)
A raw SQL string literal emitted verbatim (no parameter binding).
Use this sparingly — only for values that must appear as SQL literals
rather than positional parameters (e.g. keys in json_build_object).
The LiteralSql newtype enforces that the text is trusted, never raw
user input.
List(Vec<Expr>)
An ordered list of expressions for use in IN / NOT IN clauses.
Rendered as a comma-separated sequence; the surrounding parentheses are added by the IN/NOT IN rendering path in each dialect.
CaseWhen
CASE WHEN … THEN … ELSE NULL END.
Star
SQL wildcard * — used inside aggregate functions like COUNT(*).
Implementations§
Source§impl Expr
impl Expr
Sourcepub fn composite_field(
table: impl Into<String>,
column: impl Into<String>,
field: impl Into<String>,
json_key: impl Into<String>,
json_cast: JsonPathCast,
) -> Self
pub fn composite_field( table: impl Into<String>, column: impl Into<String>, field: impl Into<String>, json_key: impl Into<String>, json_cast: JsonPathCast, ) -> Self
Creates a reference to a field inside a composite column.
Sourcepub fn not_in_list(self, exprs: Vec<Expr>) -> Self
pub fn not_in_list(self, exprs: Vec<Expr>) -> Self
Creates a NOT IN list membership check.
Sourcepub fn function_call(name: impl Into<String>, args: Vec<Expr>) -> Self
pub fn function_call(name: impl Into<String>, args: Vec<Expr>) -> Self
Creates a function call expression.
Sourcepub fn vector_distance(metric: VectorMetric, left: Expr, right: Expr) -> Self
pub fn vector_distance(metric: VectorMetric, left: Expr, right: Expr) -> Self
Creates an internal vector-distance expression for pgvector ordering.
Sourcepub fn json_build_object(pairs: Vec<(String, Expr)>) -> Self
pub fn json_build_object(pairs: Vec<(String, Expr)>) -> Self
Creates a json_build_object() function with key-value pairs.
Keys are emitted as SQL string literals (not bound parameters) because
json_build_object requires literal key names in all supported dialects.
§Safety
Keys must be static/compile-time strings. Never pass untrusted input as
a key — use Expr::param for that and handle it in application logic.
Sourcepub fn coalesce(exprs: Vec<Expr>) -> Self
pub fn coalesce(exprs: Vec<Expr>) -> Self
Creates a COALESCE() function to return first non-NULL value.
Sourcepub fn is_not_null(self) -> Self
pub fn is_not_null(self) -> Self
Creates an IS NOT NULL check — compiles to expr IS NOT NULL.
Sourcepub fn filter(self, predicate: Expr) -> Self
pub fn filter(self, predicate: Expr) -> Self
Adds a FILTER clause to an aggregate expression (PostgreSQL).
Sourcepub fn not_exists(subquery: Select) -> Self
pub fn not_exists(subquery: Select) -> Self
Creates a NOT EXISTS subquery predicate.
Sourcepub fn relation_some(
field: impl Into<String>,
parent_table: impl Into<String>,
target_table: impl Into<String>,
fk_db: impl Into<String>,
pk_db: impl Into<String>,
filter: Expr,
) -> Self
pub fn relation_some( field: impl Into<String>, parent_table: impl Into<String>, target_table: impl Into<String>, fk_db: impl Into<String>, pk_db: impl Into<String>, filter: Expr, ) -> Self
Creates a relation some predicate.
Sourcepub fn relation_none(
field: impl Into<String>,
parent_table: impl Into<String>,
target_table: impl Into<String>,
fk_db: impl Into<String>,
pk_db: impl Into<String>,
filter: Expr,
) -> Self
pub fn relation_none( field: impl Into<String>, parent_table: impl Into<String>, target_table: impl Into<String>, fk_db: impl Into<String>, pk_db: impl Into<String>, filter: Expr, ) -> Self
Creates a relation none predicate.
Sourcepub fn relation_every(
field: impl Into<String>,
parent_table: impl Into<String>,
target_table: impl Into<String>,
fk_db: impl Into<String>,
pk_db: impl Into<String>,
filter: Expr,
) -> Self
pub fn relation_every( field: impl Into<String>, parent_table: impl Into<String>, target_table: impl Into<String>, fk_db: impl Into<String>, pk_db: impl Into<String>, filter: Expr, ) -> Self
Creates a relation every predicate.
Sourcepub fn scalar_subquery(subquery: Select) -> Self
pub fn scalar_subquery(subquery: Select) -> Self
Creates a scalar subquery expression (SELECT ...).
The inner SELECT must return exactly one column and at most one row.