Expr

Struct Expr 

Source
pub struct Expr<'column, S, T: MyTyp> { /* private fields */ }
Expand description

This is an expression that can be used in queries.

  • The lifetime parameter 'column specifies which columns need to be in scope.
  • The type parameter S specifies the expected schema of the query.
  • And finally the type paramter T specifies 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>

Source

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);
Source

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);
Source

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);
Source

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);
Source

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

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);
Source

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

impl<'column, S, T: EqTyp + 'static> Expr<'column, S, T>

Source

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);
Source

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>

Source

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);
Source

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);
Source

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

Source

pub fn unwrap_or( &self, rhs: impl IntoExpr<'column, S, Typ = Typ>, ) -> Expr<'column, S, Typ>
where Self: IntoExpr<'column, S, Typ = Option<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

pub fn is_some(&self) -> Expr<'column, S, bool>

Check that the expression is Some.

assert_eq!(txn.query_one(Some(10).into_expr().is_some()), true);
assert_eq!(txn.query_one(None::<i64>.into_expr().is_some()), false);
Source

pub fn is_none(&self) -> Expr<'column, S, bool>

Check that the expression is None.

assert_eq!(txn.query_one(Some(10).into_expr().is_none()), false);
assert_eq!(txn.query_one(None::<i64>.into_expr().is_none()), true);
Source§

impl<'column, S> Expr<'column, S, i64>

Source

pub fn as_float(&self) -> Expr<'column, S, f64>

Convert the i64 expression to f64 type.

assert_eq!(txn.query_one(10.into_expr().as_float()), 10.0);
Source§

impl<'column, S> Expr<'column, S, String>

Source

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);
Source

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);
Source

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);
Source

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);
Source

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);

Trait Implementations§

Source§

impl<S, T: MyTyp> Clone for Expr<'_, S, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S, T: MyTyp> Debug for Expr<'_, S, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

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

impl<'t, T: Table> Deref for Expr<'t, T::Schema, T>

Source§

type Target = <T as Table>::Ext2<'t>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'column, S, T: MyTyp> IntoExpr<'column, S> for Expr<'column, S, T>

Source§

type Typ = T

The type of the expression.
Source§

fn into_expr(self) -> Expr<'column, S, Self::Typ>

Turn this value into an Expr.
Source§

impl<'columns, S, T> IntoSelect<'columns, S> for Expr<'columns, S, T>
where T: MyTyp,

Source§

type Out = <T as MyTyp>::Out

The type that results from executing the Select.
Source§

fn into_select(self) -> Select<'columns, S, Self::Out>

This method is what tells rust-query how to turn the value into a Select. Read more

Auto Trait Implementations§

§

impl<'column, S, T> !Freeze for Expr<'column, S, T>

§

impl<'column, S, T> !RefUnwindSafe for Expr<'column, S, T>

§

impl<'column, S, T> !Send for Expr<'column, S, T>

§

impl<'column, S, T> !Sync for Expr<'column, S, T>

§

impl<'column, S, T> Unpin for Expr<'column, S, T>
where S: Unpin,

§

impl<'column, S, T> !UnwindSafe for Expr<'column, S, T>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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