#[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
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
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
impl Expr
Sourcepub fn col(column: impl Into<ColumnRef>) -> Expr
pub fn col(column: impl Into<ColumnRef>) -> Expr
A column reference, from "name" or ("table", "name").
Sourcepub fn tuple<V>(values: impl IntoIterator<Item = V>) -> Expr
pub fn tuple<V>(values: impl IntoIterator<Item = V>) -> Expr
A tuple of bound values.
Sourcepub fn cust_with_values<V>(
sql: impl Into<String>,
values: impl IntoIterator<Item = V>,
) -> Expr
pub fn cust_with_values<V>( sql: impl Into<String>, values: impl IntoIterator<Item = V>, ) -> Expr
Raw SQL with ? placeholders and the values that fill them, in
order.
Sourcepub fn is_not_null(self) -> Expr
pub fn is_not_null(self) -> Expr
Builds self IS NOT NULL.
Sourcepub fn like(self, pattern: impl Into<Value>) -> Expr
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.
Sourcepub fn not_like(self, pattern: impl Into<Value>) -> Expr
pub fn not_like(self, pattern: impl Into<Value>) -> Expr
Builds self NOT LIKE pattern, binding the pattern as a parameter.
Sourcepub fn like_escaped(self, pattern: impl Into<Value>, escape: char) -> Expr
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.
Sourcepub fn matches(self, query: impl Into<Value>) -> Expr
pub fn matches(self, query: impl Into<Value>) -> Expr
Builds self MATCH query for full-text search, binding the query as
a parameter.
Sourcepub fn is_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr
pub fn is_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr
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.
Sourcepub fn is_not_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr
pub fn is_not_in<V>(self, values: impl IntoIterator<Item = V>) -> Expr
Builds self NOT IN (values).
Sourcepub fn in_subquery(self, select: Select) -> Expr
pub fn in_subquery(self, select: Select) -> Expr
Builds self IN (subquery).
Sourcepub fn not_in_subquery(self, select: Select) -> Expr
pub fn not_in_subquery(self, select: Select) -> Expr
Builds self NOT IN (subquery).
Sourcepub fn between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Expr
pub fn between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Expr
Builds self BETWEEN a AND b.
Sourcepub fn not_between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Expr
pub fn not_between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Expr
Builds self NOT BETWEEN a AND b.
Sourcepub fn json_get(self, path: impl Into<Value>) -> Expr
pub fn json_get(self, path: impl Into<Value>) -> Expr
Builds self -> path, JSON extraction keeping the JSON
representation.
Sourcepub fn json_get_text(self, path: impl Into<Value>) -> Expr
pub fn json_get_text(self, path: impl Into<Value>) -> Expr
Builds self ->> path, JSON extraction yielding a SQL value.
Sourcepub fn case(whens: Vec<(Expr, Expr)>, otherwise: Option<Expr>) -> Expr
pub fn case(whens: Vec<(Expr, Expr)>, otherwise: Option<Expr>) -> Expr
Builds CASE WHEN ... THEN ... ELSE ... END.
Sourcepub fn contains(self, s: &str) -> Expr
pub fn contains(self, s: &str) -> Expr
Builds self LIKE '%s%' ESCAPE '\\', with %, _ and \\ escaped in
s so that the fragment matches literally.
Sourcepub fn starts_with(self, s: &str) -> Expr
pub fn starts_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 IntoCondition for Expr
impl IntoCondition for Expr
Source§fn into_condition(self) -> Condition
fn into_condition(self) -> Condition
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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