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>,
) -> Expr<'column, S, T>
pub fn add( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>
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>,
) -> Expr<'column, S, T>
pub fn sub( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>
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>,
) -> Expr<'column, S, T>
pub fn mul( &self, rhs: impl IntoExpr<'column, S, Typ = T>, ) -> Expr<'column, S, T>
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 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);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) -> Expr<'column, S, bool>
pub fn not(&self) -> Expr<'column, S, bool>
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>,
) -> Expr<'column, S, bool>
pub fn and( &self, rhs: impl IntoExpr<'column, S, Typ = bool>, ) -> Expr<'column, S, bool>
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);Sourcepub fn or(
&self,
rhs: impl IntoExpr<'column, S, Typ = bool>,
) -> Expr<'column, S, bool>
pub fn or( &self, rhs: impl IntoExpr<'column, S, Typ = bool>, ) -> Expr<'column, S, bool>
Check if one of two expressions is true.
assert_eq!(txn.query_one(true.into_expr().or(true)), true);
assert_eq!(txn.query_one(false.into_expr().or(true)), true);
assert_eq!(txn.query_one(false.into_expr().or(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, 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, pattern: impl AsRef<str>) -> Expr<'column, S, bool>
pub fn contains(&self, pattern: impl AsRef<str>) -> 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);