Skip to main content

Expr

Struct Expr 

Source
pub struct Expr<Req, S: SqlType> { /* private fields */ }
Expand description

A typed SQL expression. Req is the (possibly empty) flat list of tables this expression references — see the module docs and scope::Superset for how that’s checked against a query’s actual scope at the point the expression is used, not at the point it’s built. This is what lets orders::user_id.eq(users::id) be a plain, portable value with no dependency on which query it’ll eventually be used in.

Implementations§

Source§

impl<Req, S: SqlType> Expr<Req, S>

Source

pub fn decodes_as<S2: SqlType>(self) -> Declared<Req, S2>

States what this expression decodes to, which is what makes it selectable: S was inferred from whatever built the expression, and an inference can contradict the join the query actually has.

Trait Implementations§

Source§

impl<Req, S: SqlType> Clone for Expr<Req, S>

Source§

fn clone(&self) -> Self

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<Req, S: SqlType> IntoExpr for Expr<Req, S>

Source§

type Sql = S

The SQL type this expression has. An associated type rather than a parameter because every implementor has exactly one — a column its declared type, a literal its leaf type — which is what lets a mismatch report itself as Comparable/AssignsTo rather than as an inference failure on a type nobody wrote.
Source§

type Req = Req

Source§

fn into_expr(self) -> Expr<Req, S>

Source§

impl IntoRowCount for Expr<Nil, Integer>

A prepare!{} placeholder, or any other scope-free Expr of an integer type: bound rather than written, so one prepared query serves every page. Only the two integer types — a page is a number.

Source§

impl IntoRowCount for Expr<Nil, BigInt>

Source§

impl<Req, S: SqlType> LabelExt for Expr<Req, S>

Source§

fn label<K: LabelKey>(self, _key: K) -> Labeled<K, Self>

Source§

impl<Req, S: BoolLike> Not for Expr<Req, S>

!condition, not condition.not(): the standard Not trait reads more naturally at call sites than a same-named inherent method. Implemented for all three spellings .filter takes, each keeping its own type — NOT of a Nullable<Bool> is still nullable, and a sql! fragment stays the same fragment.

Source§

type Output = Expr<Req, S>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more

Auto Trait Implementations§

§

impl<Req, S> Freeze for Expr<Req, S>

§

impl<Req, S> RefUnwindSafe for Expr<Req, S>

§

impl<Req, S> Send for Expr<Req, S>
where PhantomData<fn() -> (Req, S)>: Send,

§

impl<Req, S> Sync for Expr<Req, S>
where PhantomData<fn() -> (Req, S)>: Sync,

§

impl<Req, S> Unpin for Expr<Req, S>

§

impl<Req, S> UnsafeUnpin for Expr<Req, S>

§

impl<Req, S> UnwindSafe for Expr<Req, S>

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<D, Scope, Req, Idxs, T> Condition<D, Scope, Idxs> for T
where Scope: Superset<Req, Idxs>, T: IntoExpr<Req = Req>, <T as IntoExpr>::Sql: BoolLike,

Source§

fn into_predicate(self) -> Predicate<D, Scope>

Source§

impl<T> ExprMethods for T
where T: IntoExpr,

Source§

fn eq<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: Comparable<Rhs::Sql>, Self::Req: Concat<Rhs::Req>,

Source§

fn ne<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: Comparable<Rhs::Sql>, Self::Req: Concat<Rhs::Req>,

Source§

fn lt<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: Comparable<Rhs::Sql>, Self::Req: Concat<Rhs::Req>,

Source§

fn lte<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: Comparable<Rhs::Sql>, Self::Req: Concat<Rhs::Req>,

Source§

fn gt<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: Comparable<Rhs::Sql>, Self::Req: Concat<Rhs::Req>,

Source§

fn gte<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: Comparable<Rhs::Sql>, Self::Req: Concat<Rhs::Req>,

Source§

fn is_null(self) -> Expr<Self::Req, Bool>

x IS NULL. Not expressible as .eq(..): comparing to NULL with = yields NULL, never true, so the two are different questions.
Source§

fn is_not_null(self) -> Expr<Self::Req, Bool>

Source§

fn and<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: BoolLike, Rhs::Sql: BoolLike, Self::Req: Concat<Rhs::Req>,

a AND b. The boolean requirement is on the method rather than on the receiver’s type, so every spelling a condition has — a comparison, a sql! fragment, a Nullable<Bool> column — combines with every other, the way .filter accepts them all.
Source§

fn or<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: BoolLike, Rhs::Sql: BoolLike, Self::Req: Concat<Rhs::Req>,

a OR b — see and.
Source§

fn like<Rhs: IntoExpr>( self, rhs: Rhs, ) -> Expr<<Self::Req as Concat<Rhs::Req>>::Output, Bool>
where Self::Sql: TextLike, Rhs::Sql: TextLike, Self::Req: Concat<Rhs::Req>,

x LIKE 'pattern'. The text requirement is on the method rather than on a trait of its own, so a non-text operand reports TextLike instead of a missing method.
Source§

fn is_in<I>(self, values: I) -> Expr<Self::Req, Bool>
where I: IntoIterator, I::Item: IntoExpr<Req = Nil>, Self::Sql: Comparable<<I::Item as IntoExpr>::Sql>,

x IN (a, b, ..) over a runtime-length list of literals, each bound as its own parameter. An empty list renders FALSE. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<Scope, Req, Idxs, T> GroupBy<Scope, Idxs> for T
where Scope: Superset<Req, Idxs>, T: IntoExpr<Req = Req>,

Source§

fn into_grouping(self) -> Grouping<Scope>

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> OrderExt for T
where T: IntoExpr,

Source§

fn asc(self) -> OrderKey<Self::Req>

Source§

fn sort(self, dir: SortDir) -> OrderKey<Self::Req>

The direction as a value, for a sort order that arrives at runtime — ?dir=desc — instead of an N-way match over .asc()/.desc().
Source§

fn desc(self) -> OrderKey<Self::Req>

Source§

impl<T> RawArg for T
where T: IntoExpr,

Source§

impl<S> Superset<Nil, Nil> for S

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WrapNullable<NotNull> for T