Skip to main content

Expr

Enum Expr 

Source
#[non_exhaustive]
pub enum Expr {
Show 21 variants Column(ColumnRef), Value(Value), Tuple(Vec<Expr>), Binary(Box<Expr>, BinOp, Box<Expr>), Not(Box<Expr>), Neg(Box<Expr>), IsNull(Box<Expr>), IsNotNull(Box<Expr>), In(Box<Expr>, Box<Expr>), NotIn(Box<Expr>, Box<Expr>), Between(Box<Expr>, Box<Expr>, Box<Expr>), NotBetween(Box<Expr>, Box<Expr>, Box<Expr>), Like { expr: Box<Expr>, pattern: Box<Expr>, negated: bool, escape: Option<char>, }, Func(Func), Subquery(Box<Select>), Exists(Box<Select>), Case(Vec<(Expr, Expr)>, Option<Box<Expr>>), Cast(Box<Expr>, &'static str), Alias(Box<Expr>, Ident), Raw(String, Vec<Value>), Paren(Box<Expr>),
}
Expand description

A SQL expression.

The enum is #[non_exhaustive] so that new node kinds can be added without breaking downstream matches; construct nodes through the associated functions and methods rather than the variants directly.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Column(ColumnRef)

A column reference.

§

Value(Value)

A bound value.

§

Tuple(Vec<Expr>)

A parenthesised list of expressions, for example the right-hand side of IN.

§

Binary(Box<Expr>, BinOp, Box<Expr>)

A binary operation lhs op rhs.

§

Not(Box<Expr>)

A logical negation NOT expr.

§

Neg(Box<Expr>)

An arithmetic negation -expr.

§

IsNull(Box<Expr>)

The expr IS NULL test.

§

IsNotNull(Box<Expr>)

The expr IS NOT NULL test.

§

In(Box<Expr>, Box<Expr>)

The expr IN (...) membership test.

§

NotIn(Box<Expr>, Box<Expr>)

The expr NOT IN (...) membership test.

§

Between(Box<Expr>, Box<Expr>, Box<Expr>)

The expr BETWEEN a AND b range test.

§

NotBetween(Box<Expr>, Box<Expr>, Box<Expr>)

The expr NOT BETWEEN a AND b range test.

§

Like

A pattern test expr [NOT] LIKE pattern [ESCAPE 'c'].

The escape character is carried on the node because SQLite treats a backslash in a pattern literally unless the statement says otherwise; the contains family sets it so that % and _ in user input match themselves.

Fields

§expr: Box<Expr>

The tested expression.

§pattern: Box<Expr>

The pattern, normally a bound value.

§negated: bool

Whether the test is NOT LIKE.

§escape: Option<char>

The ESCAPE character, when the pattern uses one.

§

Func(Func)

A function call name(args).

§

Subquery(Box<Select>)

A scalar subquery (SELECT ...).

§

Exists(Box<Select>)

An existence test EXISTS (SELECT ...).

§

Case(Vec<(Expr, Expr)>, Option<Box<Expr>>)

A CASE WHEN ... THEN ... ELSE ... END expression.

§

Cast(Box<Expr>, &'static str)

A type conversion CAST(expr AS type).

§

Alias(Box<Expr>, Ident)

An aliased expression expr AS alias, only meaningful in select lists.

§

Raw(String, Vec<Value>)

Raw SQL inserted verbatim, with ? placeholders for the values carried in .1.

§

Paren(Box<Expr>)

An explicitly parenthesised expression (expr).

Implementations§

Source§

impl Expr

Source

pub fn col(column: impl Into<ColumnRef>) -> Expr

A column reference, from "name" or ("table", "name").

Source

pub fn val(value: impl Into<Value>) -> Expr

A bound value.

Source

pub fn tuple<V>(values: impl IntoIterator<Item = V>) -> Expr
where V: Into<Value>,

A tuple of bound values.

Source

pub fn subquery(select: Select) -> Expr

A scalar subquery.

Source

pub fn exists(select: Select) -> Expr

An EXISTS (subquery) test.

Source

pub fn cust(sql: impl Into<String>) -> Expr

Raw SQL with ? placeholders and no values.

Source

pub fn cust_with_values<V>( sql: impl Into<String>, values: impl IntoIterator<Item = V>, ) -> Expr
where V: Into<Value>,

Raw SQL with ? placeholders and the values that fill them, in order.

Source

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

Builds self = rhs.

Source

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

Builds self <> rhs.

Source

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

Builds self < rhs.

Source

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

Builds self <= rhs.

Source

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

Builds self > rhs.

Source

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

Builds self >= rhs.

Source

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

Builds self AND rhs.

Source

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

Builds self OR rhs.

Source

pub fn not(self) -> Expr

Builds NOT self.

Source

pub fn neg(self) -> Expr

Builds -self.

Source

pub fn is_null(self) -> Expr

Builds self IS NULL.

Source

pub fn is_not_null(self) -> Expr

Builds self IS NOT NULL.

Source

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

Builds self IS rhs, the null-safe equality.

Source

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

Builds self IS NOT rhs.

Source

pub fn like(self, pattern: impl Into<Value>) -> Expr

Builds self LIKE pattern, binding the pattern as a parameter.

The pattern is taken as written: % and _ are wildcards and no ESCAPE clause is emitted. See like_escaped for a pattern that needs one.

Source

pub fn not_like(self, pattern: impl Into<Value>) -> Expr

Builds self NOT LIKE pattern, binding the pattern as a parameter.

Source

pub fn like_escaped(self, pattern: impl Into<Value>, escape: char) -> Expr

Builds self LIKE pattern ESCAPE 'escape', for a pattern in which escape precedes every wildcard that must match literally.

Source

pub fn matches(self, query: impl Into<Value>) -> Expr

Builds self MATCH query for full-text search, binding the query as a parameter.

Source

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

Builds self IN (values).

An empty list renders as IN (NULL), which matches nothing, so a filter built from an empty collection behaves as expected instead of producing a syntax error.

Source

pub fn is_not_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr
where V: Into<Value>,

Builds self NOT IN (values).

Source

pub fn in_subquery(self, select: Select) -> Expr

Builds self IN (subquery).

Source

pub fn not_in_subquery(self, select: Select) -> Expr

Builds self NOT IN (subquery).

Source

pub fn between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Expr

Builds self BETWEEN a AND b.

Source

pub fn not_between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Expr

Builds self NOT BETWEEN a AND b.

Source

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

Builds self + rhs.

Source

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

Builds self - rhs.

Source

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

Builds self * rhs.

Source

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

Builds self / rhs.

Source

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

Builds self % rhs.

Source

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

Builds self || rhs.

Source

pub fn json_get(self, path: impl Into<Value>) -> Expr

Builds self -> path, JSON extraction keeping the JSON representation.

Source

pub fn json_get_text(self, path: impl Into<Value>) -> Expr

Builds self ->> path, JSON extraction yielding a SQL value.

Source

pub fn cast_as(self, ty: &'static str) -> Expr

Builds CAST(self AS type).

Source

pub fn alias(self, alias: impl IntoIden) -> Expr

Builds self AS alias.

Source

pub fn paren(self) -> Expr

Builds (self).

Source

pub fn case(whens: Vec<(Expr, Expr)>, otherwise: Option<Expr>) -> Expr

Builds CASE WHEN ... THEN ... ELSE ... END.

Source

pub fn contains(self, s: &str) -> Expr

Builds self LIKE '%s%' ESCAPE '\\', with %, _ and \\ escaped in s so that the fragment matches literally.

Source

pub fn starts_with(self, s: &str) -> Expr

Builds self LIKE 's%' ESCAPE '\\', with %, _ and \\ escaped in s so that the fragment matches literally.

Source

pub fn ends_with(self, s: &str) -> Expr

Builds self LIKE '%s' ESCAPE '\\', with %, _ and \\ escaped in s so that the fragment matches literally.

Trait Implementations§

Source§

impl Build for Expr

Source§

fn to_statement(&self) -> Statement

Renders into a Statement.
Source§

fn build(&self) -> (String, Vec<Value>)

Renders to the SQL text and the values to bind.
Source§

fn to_string_inlined(&self) -> String

Renders with literals inlined, for logs and tests only.
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<(), Error>

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

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

Source§

fn from(value: T) -> Expr

Converts to this type from the input type.
Source§

impl IntoCondition for Expr

Source§

fn into_condition(self) -> Condition

Converts into a condition.
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 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

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

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