#[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>) -> Self
pub fn col(column: impl Into<ColumnRef>) -> Self
A column reference, from "name" or ("table", "name").
Sourcepub fn tuple<V: Into<Value>>(values: impl IntoIterator<Item = V>) -> Self
pub fn tuple<V: Into<Value>>(values: impl IntoIterator<Item = V>) -> Self
A tuple of bound values.
Sourcepub fn cust_with_values<V: Into<Value>>(
sql: impl Into<String>,
values: impl IntoIterator<Item = V>,
) -> Self
pub fn cust_with_values<V: Into<Value>>( sql: impl Into<String>, values: impl IntoIterator<Item = V>, ) -> Self
Raw SQL with ? placeholders and the values that fill them, in
order.
Sourcepub fn is_not_null(self) -> Self
pub fn is_not_null(self) -> Self
Builds self IS NOT NULL.
Sourcepub fn like(self, pattern: impl Into<Value>) -> Self
pub fn like(self, pattern: impl Into<Value>) -> Self
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>) -> Self
pub fn not_like(self, pattern: impl Into<Value>) -> Self
Builds self NOT LIKE pattern, binding the pattern as a parameter.
Sourcepub fn like_escaped(self, pattern: impl Into<Value>, escape: char) -> Self
pub fn like_escaped(self, pattern: impl Into<Value>, escape: char) -> Self
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>) -> Self
pub fn matches(self, query: impl Into<Value>) -> Self
Builds self MATCH query for full-text search, binding the query as
a parameter.
Sourcepub fn is_in<V: Into<Value>>(self, values: impl IntoIterator<Item = V>) -> Self
pub fn is_in<V: Into<Value>>(self, values: impl IntoIterator<Item = V>) -> Self
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: Into<Value>>(
self,
values: impl IntoIterator<Item = V>,
) -> Self
pub fn is_not_in<V: Into<Value>>( self, values: impl IntoIterator<Item = V>, ) -> Self
Builds self NOT IN (values).
Sourcepub fn in_subquery(self, select: Select) -> Self
pub fn in_subquery(self, select: Select) -> Self
Builds self IN (subquery).
Sourcepub fn not_in_subquery(self, select: Select) -> Self
pub fn not_in_subquery(self, select: Select) -> Self
Builds self NOT IN (subquery).
Sourcepub fn between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Self
pub fn between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Self
Builds self BETWEEN a AND b.
Sourcepub fn not_between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Self
pub fn not_between(self, a: impl Into<Expr>, b: impl Into<Expr>) -> Self
Builds self NOT BETWEEN a AND b.
Sourcepub fn json_get(self, path: impl Into<Value>) -> Self
pub fn json_get(self, path: impl Into<Value>) -> Self
Builds self -> path, JSON extraction keeping the JSON
representation.
Sourcepub fn json_get_text(self, path: impl Into<Value>) -> Self
pub fn json_get_text(self, path: impl Into<Value>) -> Self
Builds self ->> path, JSON extraction yielding a SQL value.
Sourcepub fn case(whens: Vec<(Expr, Expr)>, otherwise: Option<Expr>) -> Self
pub fn case(whens: Vec<(Expr, Expr)>, otherwise: Option<Expr>) -> Self
Builds CASE WHEN ... THEN ... ELSE ... END.
Sourcepub fn contains(self, s: &str) -> Self
pub fn contains(self, s: &str) -> Self
Builds self LIKE '%s%' ESCAPE '\\', with %, _ and \\ escaped in
s so that the fragment matches literally.
Sourcepub fn starts_with(self, s: &str) -> Self
pub fn starts_with(self, s: &str) -> Self
Builds self LIKE 's%' ESCAPE '\\', with %, _ and \\ escaped in
s so that the fragment matches literally.