Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 17 variants Column(Column), Value(Value), Binary { op: BinaryOp, lhs: Box<Expr>, rhs: Box<Expr>, }, Unary { op: UnaryOp, expr: Box<Expr>, }, And(Vec<Expr>), Or(Vec<Expr>), Lookup { expr: Box<Expr>, lookup: Lookup, }, Exists(Box<QueryPlan>), Subquery(Box<QueryPlan>), Func { func: Function, args: Vec<Expr>, }, Cast { expr: Box<Expr>, ty: SqlType, }, Case { branches: Vec<(Expr, Expr)>, otherwise: Option<Box<Expr>>, }, Aggregate(Aggregate), Window(Box<Window>), DatePart { part: DatePart, expr: Box<Expr>, }, OuterRef(Column), Related(RelatedColumn),
}
Expand description

Expression tree node.

Variants§

§

Column(Column)

Column reference (Django F).

§

Value(Value)

Literal, always bound as a parameter.

§

Binary

Binary operation.

Fields

§op: BinaryOp

Operator.

§lhs: Box<Expr>

Left operand.

§rhs: Box<Expr>

Right operand.

§

Unary

Unary operation.

Fields

§op: UnaryOp

Operator.

§expr: Box<Expr>

Operand.

§

And(Vec<Expr>)

Conjunction of all children (empty = TRUE).

§

Or(Vec<Expr>)

Disjunction of all children (empty = FALSE).

§

Lookup

Lookup applied to an expression.

Fields

§expr: Box<Expr>

Target expression.

§lookup: Lookup

Lookup.

§

Exists(Box<QueryPlan>)

EXISTS (subquery).

§

Subquery(Box<QueryPlan>)

Scalar subquery.

§

Func

Scalar function call.

Fields

§func: Function

Function.

§args: Vec<Expr>

Arguments.

§

Cast

CAST(expr AS type).

Fields

§expr: Box<Expr>

Operand.

§ty: SqlType

Target type family.

§

Case

Searched CASE WHEN .. THEN .. [ELSE ..] END.

Fields

§branches: Vec<(Expr, Expr)>

(condition, result) branches, tried in order.

§otherwise: Option<Box<Expr>>

ELSE result (NULL when absent).

§

Aggregate(Aggregate)

Aggregate function (COUNT, SUM, …).

§

Window(Box<Window>)

Window function with its OVER (..) clause.

§

DatePart

Date or time component of a temporal expression.

Fields

§part: DatePart

Component to extract.

§expr: Box<Expr>

Temporal operand.

§

OuterRef(Column)

Column of the enclosing query, used inside a correlated subquery.

§

Related(RelatedColumn)

Column reached through foreign keys; resolved into joins by QueryPlan::resolve_relations.

Implementations§

Source§

impl Expr

Source

pub fn year(self) -> Expr

The Year component of a temporal expression.

Source

pub fn month(self) -> Expr

The Month component of a temporal expression.

Source

pub fn day(self) -> Expr

The Day component of a temporal expression.

Source

pub fn week(self) -> Expr

The Week component of a temporal expression.

Source

pub fn quarter(self) -> Expr

The Quarter component of a temporal expression.

Source

pub fn hour(self) -> Expr

The Hour component of a temporal expression.

Source

pub fn minute(self) -> Expr

The Minute component of a temporal expression.

Source

pub fn second(self) -> Expr

The Second component of a temporal expression.

Source

pub fn date(self) -> Expr

The Date component of a temporal expression.

Source§

impl Expr

Source

pub fn col(name: impl Into<Ident>) -> Self

Column expression on the root source.

Source

pub fn val(v: impl Into<Value>) -> Self

Literal value expression.

Source

pub fn outer(name: impl Into<Ident>) -> Self

Reference to a column of the enclosing query (Django OuterRef).

Source

pub fn exists(plan: QueryPlan) -> Self

EXISTS (plan).

Source

pub fn subquery(plan: QueryPlan) -> Self

Scalar subquery: plan must select exactly one column and one row.

Source

pub fn eq(self, rhs: impl Into<Expr>) -> Self

self = rhs. A NULL right-hand side compiles to IS NULL.

Source

pub fn ne(self, rhs: impl Into<Expr>) -> Self

self <> rhs. A NULL right-hand side compiles to IS NOT NULL.

Source

pub fn lt(self, rhs: impl Into<Expr>) -> Self

self < rhs.

Source

pub fn le(self, rhs: impl Into<Expr>) -> Self

self <= rhs.

Source

pub fn gt(self, rhs: impl Into<Expr>) -> Self

self > rhs.

Source

pub fn ge(self, rhs: impl Into<Expr>) -> Self

self >= rhs.

Source

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

Logical AND; flattens nested ANDs.

Source

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

Logical OR; flattens nested ORs.

Source

pub fn is_in<I, V>(self, values: I) -> Self
where I: IntoIterator<Item = V>, V: Into<Value>,

Membership test.

Source

pub fn in_subquery(self, plan: QueryPlan) -> Self

Membership in the single column selected by plan.

Source

pub fn range(self, lo: impl Into<Value>, hi: impl Into<Value>) -> Self

Inclusive range.

Source

pub fn is_null(self, yes: bool) -> Self

IS NULL / IS NOT NULL.

Source

pub fn iexact(self, v: impl Into<Value>) -> Self

Case-insensitive equality (text).

Source

pub fn regex(self, pattern: impl Into<String>) -> Self

Regex match (requires Feature::Regex).

Source

pub fn cast(self, ty: SqlType) -> Self

CAST(self AS ty).

Source

pub fn date_part(self, part: DatePart) -> Self

Extract a date or time component.

Source

pub fn asc(self) -> OrderExpr

Ascending ordering term.

Source

pub fn desc(self) -> OrderExpr

Descending ordering term.

Source

pub fn children(&self) -> Vec<&Expr>

Direct sub-expressions (subquery plans are reached through subplan instead).

Source

pub fn children_mut(&mut self) -> Vec<&mut Expr>

Mutable counterpart of children.

Source

pub fn subplan(&self) -> Option<&QueryPlan>

The nested query of EXISTS, a scalar subquery or IN (subquery).

Source

pub fn subplan_mut(&mut self) -> Option<&mut QueryPlan>

Mutable counterpart of subplan.

Source

pub fn contains_aggregate(&self) -> bool

Whether this expression computes an aggregate over the query’s rows (so a filter on it belongs in HAVING). Aggregates inside window functions and subqueries do not count.

Source

pub fn contains_window(&self) -> bool

Whether this expression contains a window function.

Source§

impl Expr

Source

pub fn has_foreign_origin(&self, origin: PlanOrigin) -> bool

Whether a subquery inside this expression was built against a database other than origin.

Source

pub fn required_features(&self) -> Vec<Feature>

Features this expression (including nested subqueries) needs.

Trait Implementations§

Source§

impl<R: Into<Expr>> Add<R> for Expr

Source§

type Output = Expr

The resulting type after applying the + operator.
Source§

fn add(self, rhs: R) -> Expr

Performs the + operation. Read more
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<R: Into<Expr>> Div<R> for Expr

Source§

type Output = Expr

The resulting type after applying the / operator.
Source§

fn div(self, rhs: R) -> Expr

Performs the / operation. Read more
Source§

impl From<Aggregate> for Expr

Source§

fn from(agg: Aggregate) -> Self

Converts to this type from the input type.
Source§

impl<M, T> From<Calc<M, T>> for Expr

Source§

fn from(c: Calc<M, T>) -> Self

Converts to this type from the input type.
Source§

impl<M, T> From<Field<M, T>> for Expr

Source§

fn from(f: Field<M, T>) -> Self

Converts to this type from the input type.
Source§

impl<M, T> From<Joined<M, T>> for Expr

Source§

fn from(j: Joined<M, T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<T> for Expr

Source§

fn from(v: T) -> Self

Converts to this type from the input type.
Source§

impl From<Window> for Expr

Source§

fn from(window: Window) -> Self

Converts to this type from the input type.
Source§

impl<R: Into<Expr>> Mul<R> for Expr

Source§

type Output = Expr

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: R) -> Expr

Performs the * operation. Read more
Source§

impl Neg for Expr

Source§

type Output = Expr

The resulting type after applying the - operator.
Source§

fn neg(self) -> Expr

Performs the unary - operation. Read more
Source§

impl Not for Expr

Source§

type Output = Expr

The resulting type after applying the ! operator.
Source§

fn not(self) -> Expr

Performs the unary ! operation. Read more
Source§

impl PartialEq for Expr

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<R: Into<Expr>> Rem<R> for Expr

Source§

type Output = Expr

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: R) -> Expr

Performs the % operation. Read more
Source§

impl StructuralPartialEq for Expr

Source§

impl<R: Into<Expr>> Sub<R> for Expr

Source§

type Output = Expr

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: R) -> Expr

Performs the - operation. Read more

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more