pub struct Expr<'column, S, T: MyTyp> { /* private fields */ }Expand description
This is an expression that can be used in queries.
- The lifetime parameter
'columnspecifies which columns need to be in scope. - The type parameter
Sspecifies the expected schema of the query. - And finally the type paramter
Tspecifies the type of the expression.
Expr implements Deref to have column fields in case the expression has a table type.
Implementations§
Source§impl<'column, S, T: NumTyp> Expr<'column, S, T>
impl<'column, S, T: NumTyp> Expr<'column, S, T>
Sourcepub fn add(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
pub fn add(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
Add two expressions together.
assert_eq!(txn.query_one(1.into_expr().add(2)), 3);
assert_eq!(txn.query_one(1.0.into_expr().add(2.0)), 3.0);Sourcepub fn sub(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
pub fn sub(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
Subtract one expression from another.
assert_eq!(txn.query_one(1.into_expr().sub(2)), -1);
assert_eq!(txn.query_one(1.0.into_expr().sub(2.0)), -1.0);Sourcepub fn mul(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
pub fn mul(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
Multiply two expressions together.
assert_eq!(txn.query_one(2.into_expr().mul(3)), 6);
assert_eq!(txn.query_one(2.0.into_expr().mul(3.0)), 6.0);Sourcepub fn div(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
pub fn div(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
Divide one expression by another.
For integers, the result is truncated towards zero. See also Expr::modulo.
assert_eq!(txn.query_one(5.into_expr().div(3)), 1);
assert_eq!(txn.query_one((-5).into_expr().div(3)), -1);
assert_eq!(txn.query_one(1.0.into_expr().div(2.0)), 0.5);Sourcepub fn lt(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn lt( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Compute the less than operator (<) of two expressions.
assert_eq!(txn.query_one(2.into_expr().lt(3)), true);
assert_eq!(txn.query_one(1.into_expr().lt(1)), false);
assert_eq!(txn.query_one(3.0.into_expr().lt(1.0)), false);Sourcepub fn lte(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn lte( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Compute the less than or equal operator (<=) of two expressions.
assert_eq!(txn.query_one(2.into_expr().lte(2)), true);
assert_eq!(txn.query_one(3.0.into_expr().lte(1.0)), false);Sourcepub fn gt(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn gt( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Compute the greater than operator (>) of two expressions.
assert_eq!(txn.query_one(2.into_expr().gt(2)), false);
assert_eq!(txn.query_one(3.0.into_expr().gt(1.0)), true);Sourcepub fn gte(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn gte( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Compute the greater than or equal (>=) operator of two expressions.
assert_eq!(txn.query_one(2.into_expr().gte(3)), false);
assert_eq!(txn.query_one(3.0.into_expr().gte(3.0)), true);Sourcepub fn max(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
pub fn max(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
Get the maximum of two values.
assert_eq!(txn.query_one(2.into_expr().max(3)), 3);
assert_eq!(txn.query_one(5.0.into_expr().max(3.0)), 5.0);Sourcepub fn min(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
pub fn min(&self, rhs: impl IntoExpr<'column, S, Typ = T>) -> Self
Get the minimum of two values.
assert_eq!(txn.query_one(2.into_expr().min(3)), 2);
assert_eq!(txn.query_one(5.0.into_expr().min(3.0)), 3.0);Sourcepub fn sign(&self) -> Expr<'column, S, i64>
pub fn sign(&self) -> Expr<'column, S, i64>
Get the sign of the expression.
The result is -1, 0 or 1 depending on if the expression is negative, zero or positive.
assert_eq!(txn.query_one(2.into_expr().sign()), 1);
assert_eq!(txn.query_one((-5.0).into_expr().sign()), -1);
assert_eq!(txn.query_one((-0.0).into_expr().sign()), 0);Sourcepub fn abs(&self) -> Self
pub fn abs(&self) -> Self
Get the absolute value of the expression.
assert_eq!(txn.query_one(2.into_expr().abs()), 2);
assert_eq!(txn.query_one((-5.0).into_expr().abs()), 5.0);Sourcepub fn between(
&self,
low: impl IntoExpr<'column, S, Typ = T>,
high: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn between( &self, low: impl IntoExpr<'column, S, Typ = T>, high: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Check if a value is between two other values.
The range is inclusive on both sides.
assert_eq!(txn.query_one(2.into_expr().between(2, 3)), true);
assert_eq!(txn.query_one(3.into_expr().between(2, 3)), true);
assert_eq!(txn.query_one(5.into_expr().between(2, 3)), false);
assert_eq!(txn.query_one(1.into_expr().between(2, 3)), false);Source§impl<'column, S, T: EqTyp + 'static> Expr<'column, S, T>
impl<'column, S, T: EqTyp + 'static> Expr<'column, S, T>
Sourcepub fn eq(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn eq( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Check whether two expressions are equal.
assert_eq!(txn.query_one(2.into_expr().eq(2)), true);
assert_eq!(txn.query_one(3.0.into_expr().eq(3.0)), true);
assert_eq!(txn.query_one("test".into_expr().eq("test")), true);
assert_eq!(txn.query_one(b"test".into_expr().eq(b"test" as &[u8])), true);
assert_eq!(txn.query_one(false.into_expr().eq(false)), true);
assert_eq!(txn.query_one(1.into_expr().eq(2)), false);Sourcepub fn neq(
&self,
rhs: impl IntoExpr<'column, S, Typ = T>,
) -> Expr<'column, S, bool>
pub fn neq( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, bool>
Check whether two expressions are not equal.
assert_eq!(txn.query_one(2.into_expr().neq(2)), false);
assert_eq!(txn.query_one(3.0.into_expr().neq(3.1)), true);
assert_eq!(txn.query_one("test".into_expr().neq("test")), false);
assert_eq!(txn.query_one(b"test".into_expr().neq(b"test" as &[u8])), false);
assert_eq!(txn.query_one(false.into_expr().neq(false)), false);
assert_eq!(txn.query_one(1.into_expr().neq(2)), true);Source§impl<'column, S> Expr<'column, S, bool>
impl<'column, S> Expr<'column, S, bool>
Sourcepub fn not(&self) -> Self
pub fn not(&self) -> Self
Checks whether an expression is false.
assert_eq!(txn.query_one(true.into_expr().not()), false);
assert_eq!(txn.query_one(false.into_expr().not()), true);Sourcepub fn and(&self, rhs: impl IntoExpr<'column, S, Typ = bool>) -> Self
pub fn and(&self, rhs: impl IntoExpr<'column, S, Typ = bool>) -> Self
Check if two expressions are both true.
assert_eq!(txn.query_one(true.into_expr().and(true)), true);
assert_eq!(txn.query_one(false.into_expr().and(true)), false);
assert_eq!(txn.query_one(false.into_expr().and(false)), false);Source§impl<'column, S, Typ: MyTyp> Expr<'column, S, Option<Typ>>
impl<'column, S, Typ: MyTyp> Expr<'column, S, Option<Typ>>
Sourcepub fn unwrap_or(
&self,
rhs: impl IntoExpr<'column, S, Typ = Typ>,
) -> Expr<'column, S, Typ>
pub fn unwrap_or( &self, rhs: impl IntoExpr<'column, S, Typ = Typ>, ) -> Expr<'column, S, Typ>
Use the first expression if it is Some, otherwise use the second expression.
assert_eq!(txn.query_one(Some(10).into_expr().unwrap_or(5)), 10);
assert_eq!(txn.query_one(None::<String>.into_expr().unwrap_or("foo")), "foo");Source§impl<'column, S> Expr<'column, S, i64>
impl<'column, S> Expr<'column, S, i64>
Sourcepub fn modulo(&self, rhs: impl IntoExpr<'column, S, Typ = i64>) -> Self
pub fn modulo(&self, rhs: impl IntoExpr<'column, S, Typ = i64>) -> Self
Calculate the remainder for integer division.
The remainder is the missing part after division.
assert_eq!(txn.query_one(5.into_expr().div(3)), 1);
assert_eq!(txn.query_one(5.into_expr().modulo(3)), 2);
assert_eq!(txn.query_one((-5).into_expr().div(3)), -1);
assert_eq!(txn.query_one((-5).into_expr().modulo(3)), -2);Sourcepub fn unix_epoch() -> Self
pub fn unix_epoch() -> Self
Get the current timestamp as milliseconds since unix epoch.
Source§impl<'column, S> Expr<'column, S, String>
impl<'column, S> Expr<'column, S, String>
Sourcepub fn starts_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
pub fn starts_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
Check if the expression starts with the string pattern.
Matches case-sensitive. The pattern gets automatically escaped.
assert_eq!(txn.query_one("hello world".into_expr().starts_with("hello")), true);
assert_eq!(txn.query_one("hello world".into_expr().starts_with("Hello")), false);Sourcepub fn ends_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
pub fn ends_with(&self, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
Check if the expression ends with the string pattern.
Matches case-sensitive. The pattern gets automatically escaped.
assert_eq!(txn.query_one("hello world".into_expr().ends_with("world")), true);
assert_eq!(txn.query_one("hello world".into_expr().ends_with("World")), false);Sourcepub fn contains(
&self,
rhs: impl IntoExpr<'column, S, Typ = String>,
) -> Expr<'column, S, bool>
pub fn contains( &self, rhs: impl IntoExpr<'column, S, Typ = String>, ) -> Expr<'column, S, bool>
Check if the expression contains the string pattern.
Matches case-sensitive. The pattern gets automatically escaped.
assert_eq!(txn.query_one("rhubarb".into_expr().contains("bar")), true);
assert_eq!(txn.query_one("rhubarb".into_expr().contains("Bar")), false);Sourcepub fn glob(
&self,
rhs: impl IntoExpr<'column, S, Typ = String>,
) -> Expr<'column, S, bool>
pub fn glob( &self, rhs: impl IntoExpr<'column, S, Typ = String>, ) -> Expr<'column, S, bool>
Check if the expression matches the pattern sqlite docs.
This is a case-sensitive version of like. It uses Unix file globbing syntax for wild
cards. * matches any sequence of characters and ? matches any single character. [0-9] matches
any single digit and [a-z] matches any single lowercase letter. ^ negates the pattern.
assert_eq!(txn.query_one("hello world".into_expr().glob("?ello*")), true);
assert_eq!(txn.query_one("hello world".into_expr().glob("Hell*")), false);Sourcepub fn like(&self, pattern: impl Into<String>) -> Expr<'column, S, bool>
pub fn like(&self, pattern: impl Into<String>) -> Expr<'column, S, bool>
Check if the expression matches the pattern sqlite docs.
As noted in the docs, it is case-insensitive for ASCII characters. Other characters are case-sensitive.
For creating patterns it uses % as a wildcard for any sequence of characters and _ for any single character.
Special characters should be escaped with \.
assert_eq!(txn.query_one("hello world".into_expr().like("HELLO%")), true);
assert_eq!(txn.query_one("hello world".into_expr().like("he_o%")), false);Sourcepub fn concat(&self, rhs: impl IntoExpr<'column, S, Typ = String>) -> Self
pub fn concat(&self, rhs: impl IntoExpr<'column, S, Typ = String>) -> Self
Concatenate two strings.
assert_eq!(txn.query_one("hello ".into_expr().concat("world").concat("!")), "hello world!");Sourcepub fn lower(&self) -> Self
pub fn lower(&self) -> Self
Convert ascii to lowercase.
assert_eq!(txn.query_one("Hello".into_expr().lower()), "hello");
assert_eq!(txn.query_one("WHAT".into_expr().lower()), "what");Source§impl<'column, S, T: BuffTyp> Expr<'column, S, T>
impl<'column, S, T: BuffTyp> Expr<'column, S, T>
Sourcepub fn byte_len(&self) -> Expr<'column, S, i64>
pub fn byte_len(&self) -> Expr<'column, S, i64>
The length of the value in bytes.
The byte length of strings can depend on the encoding (UTF-8 or UTF-16).
assert_eq!(txn.query_one("€".into_expr().byte_len()), 3);
assert_eq!(txn.query_one("what".into_expr().byte_len()), 4);
assert_eq!(txn.query_one(vec![1, 2].into_expr().byte_len()), 2);