Trait diesel::expression::expression_methods::global_expression_methods::ExpressionMethods
[−]
[src]
pub trait ExpressionMethods: Expression + Sized { fn aliased<'a>(self, alias: &'a str) -> Aliased<'a, Self> { ... } fn eq<T: AsExpression<Self::SqlType>>(self, other: T) -> Eq<Self, T::Expression> { ... } fn ne<T: AsExpression<Self::SqlType>>(self, other: T) -> NotEq<Self, T::Expression> { ... } fn is_null(self) -> IsNull<Self> { ... } fn is_not_null(self) -> IsNotNull<Self> { ... } fn gt<T: AsExpression<Self::SqlType>>(self, other: T) -> Gt<Self, T::Expression> { ... } fn ge<T: AsExpression<Self::SqlType>>(self, other: T) -> GtEq<Self, T::Expression> { ... } fn lt<T: AsExpression<Self::SqlType>>(self, other: T) -> Lt<Self, T::Expression> { ... } fn le<T: AsExpression<Self::SqlType>>(self, other: T) -> LtEq<Self, T::Expression> { ... } fn between<T: AsExpression<Self::SqlType>>(self, other: Range<T>) -> Between<Self, And<T::Expression, T::Expression>> { ... } fn not_between<T: AsExpression<Self::SqlType>>(self, other: Range<T>) -> NotBetween<Self, And<T::Expression, T::Expression>> { ... } fn desc(self) -> Desc<Self> { ... } fn asc(self) -> Asc<Self> { ... } }
Provided Methods
fn aliased<'a>(self, alias: &'a str) -> Aliased<'a, Self>
Alias an expression for use alongside
with
.
While you will need to give it a name to alias as, you should not need to reference the alias elsewhere. You can pass the returned expression anywhere you want to reference the alias.
Example
let query = plain_to_tsquery(search_text).aliased("q"); let rank = ts_rank(query, indexed_search_column).aliased("rank"); crates.with(query).with(rank) .filter(query.matches(indexed_search_column)) .order(rank.desc())
fn eq<T: AsExpression<Self::SqlType>>(self, other: T) -> Eq<Self, T::Expression>
Creates a SQL =
expression.
Example
let data = users.select(id).filter(name.eq("Sean")); assert_eq!(Some(1), data.first(&connection).unwrap());
fn ne<T: AsExpression<Self::SqlType>>(self, other: T) -> NotEq<Self, T::Expression>
Creates a SQL !=
expression.
Example
let data = users.select(id).filter(name.ne("Sean")); assert_eq!(Some(2), data.first(&connection).unwrap());
fn is_null(self) -> IsNull<Self>
Creates a SQL IS NULL
expression.
fn is_not_null(self) -> IsNotNull<Self>
Creates a SQL IS NOT NULL
expression.
fn gt<T: AsExpression<Self::SqlType>>(self, other: T) -> Gt<Self, T::Expression>
Creates a SQL >
expression.
Example
let data = users.select(name).filter(id.gt(1)); assert_eq!(Some("Tess".to_string()), data.first(&connection).unwrap());
fn ge<T: AsExpression<Self::SqlType>>(self, other: T) -> GtEq<Self, T::Expression>
Creates a SQL >=
expression.
Example
let data = users.select(name).filter(id.ge(2)); assert_eq!(Some("Tess".to_string()), data.first(&connection).unwrap());
fn lt<T: AsExpression<Self::SqlType>>(self, other: T) -> Lt<Self, T::Expression>
Creates a SQL <
expression.
Example
let data = users.select(name).filter(id.lt(2)); assert_eq!(Some("Sean".to_string()), data.first(&connection).unwrap());
fn le<T: AsExpression<Self::SqlType>>(self, other: T) -> LtEq<Self, T::Expression>
Creates a SQL <=
expression.
Example
let data = users.select(name).filter(id.le(2)); assert_eq!(Some("Sean".to_string()), data.first(&connection).unwrap());
fn between<T: AsExpression<Self::SqlType>>(self, other: Range<T>) -> Between<Self, And<T::Expression, T::Expression>>
Creates a SQL BETWEEN
expression using the given range.
fn not_between<T: AsExpression<Self::SqlType>>(self, other: Range<T>) -> NotBetween<Self, And<T::Expression, T::Expression>>
Creates a SQL NOT BETWEEN
expression using the given range.
fn desc(self) -> Desc<Self>
Creates a SQL DESC
expression, representing this expression in
descending order.
fn asc(self) -> Asc<Self>
Creates a SQL ASC
expression, representing this expression in
descending order.
This is the same as leaving the direction unspecified. It is useful if you need to provide an unknown ordering, and need to box the return value of a function.
Example
let ordering: Box<BoxableExpression<users, (), SqlType=()>> = if order == "name" { Box::new(name.desc()) } else { Box::new(id.asc()) };
Implementors
impl<T: Expression> ExpressionMethods for T