Skip to main content

Expr

Enum Expr 

Source
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

§table: String

Database table name.

§column: String

Database column name containing the composite/JSON value.

§field: String

Database field name inside the PostgreSQL composite type.

§json_key: String

JSON object key used by JSON-backed composite storage.

§json_cast: JsonPathCast

Optional cast hint for JSON-backed providers.

§

Param(Value)

Parameter placeholder.

§

Binary

Binary operation.

Fields

§left: Box<Expr>

Left operand.

§op: BinaryOp

Operator.

§right: Box<Expr>

Right operand.

§

Not(Box<Expr>)

Logical NOT.

§

FunctionCall

Function call (e.g., json_agg, COALESCE).

Fields

§name: String

Function name.

§args: Vec<Expr>

Function arguments.

§

Filter

SQL FILTER clause for aggregate functions (PostgreSQL).

Fields

§expr: Box<Expr>

The aggregation expression.

§predicate: Box<Expr>

The filter predicate.

§

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: RelationFilterOp

Which 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.

Fields

§condition: Box<Expr>

The condition.

§then: Box<Expr>

The THEN result.

§

Star

SQL wildcard * — used inside aggregate functions like COUNT(*).

Implementations§

Source§

impl Expr

Source

pub fn column(name: impl Into<String>) -> Self

Creates a column reference.

Source

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.

Source

pub fn param(value: impl Into<Value>) -> Self

Creates a parameter placeholder.

Source

pub fn eq(self, other: Expr) -> Self

Creates an equality comparison (=).

Source

pub fn ne(self, other: Expr) -> Self

Creates a not-equal comparison (!=).

Source

pub fn lt(self, other: Expr) -> Self

Creates a less-than comparison (<).

Source

pub fn le(self, other: Expr) -> Self

Creates a less-than-or-equal comparison (<=).

Source

pub fn gt(self, other: Expr) -> Self

Creates a greater-than comparison (>).

Source

pub fn ge(self, other: Expr) -> Self

Creates a greater-than-or-equal comparison (>=).

Source

pub fn and(self, other: Expr) -> Self

Creates a logical AND.

Source

pub fn or(self, other: Expr) -> Self

Creates a logical OR.

Source

pub fn like(self, pattern: Expr) -> Self

Creates a LIKE pattern match.

Source

pub fn in_list(self, exprs: Vec<Expr>) -> Self

Creates an IN list membership check.

Source

pub fn not_in_list(self, exprs: Vec<Expr>) -> Self

Creates a NOT IN list membership check.

Source

pub fn function_call(name: impl Into<String>, args: Vec<Expr>) -> Self

Creates a function call expression.

Source

pub fn vector_distance(metric: VectorMetric, left: Expr, right: Expr) -> Self

Creates an internal vector-distance expression for pgvector ordering.

Source

pub fn json_agg(expr: Expr) -> Self

Creates a json_agg() aggregate function.

Source

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.

Source

pub fn coalesce(exprs: Vec<Expr>) -> Self

Creates a COALESCE() function to return first non-NULL value.

Source

pub fn is_not_null(self) -> Self

Creates an IS NOT NULL check — compiles to expr IS NOT NULL.

Source

pub fn is_null(self) -> Self

Creates an IS NULL check — compiles to expr IS NULL.

Source

pub fn filter(self, predicate: Expr) -> Self

Adds a FILTER clause to an aggregate expression (PostgreSQL).

Source

pub fn exists(subquery: Select) -> Self

Creates an EXISTS subquery predicate.

Source

pub fn not_exists(subquery: Select) -> Self

Creates a NOT EXISTS subquery predicate.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn case_when(condition: Expr, then: Expr) -> Self

Creates a CASE WHEN condition THEN result ELSE NULL END expression.

Source

pub fn star() -> Self

Creates the SQL wildcard * (for use in COUNT(*)).

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<Column<T>> for Expr

Source§

fn from(col: Column<T>) -> Expr

Converts a typed column into an expression.

§Examples
use nautilus_core::{Column, Expr};

let id: Column<i64> = Column::new("users", "id");
let expr: Expr = id.into();
Source§

impl Not for Expr

Implements the ! operator for expressions, producing a SQL NOT clause.

Source§

type Output = Expr

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.