Struct diesel::expression::CaseWhen
source · pub struct CaseWhen<Whens, E> { /* private fields */ }
Expand description
A SQL CASE WHEN ... END
expression
Implementations§
source§impl<Whens, E> CaseWhen<Whens, E>
impl<Whens, E> CaseWhen<Whens, E>
sourcepub fn when<C, T>(self, condition: C, if_true: T) -> When<Self, C, T>where
Self: CaseWhenTypesExtractor<Whens = Whens, Else = E>,
C: Expression,
<C as Expression>::SqlType: BoolOrNullableBool,
T: AsExpression<<Self as CaseWhenTypesExtractor>::OutputExpressionSpecifiedSqlType>,
pub fn when<C, T>(self, condition: C, if_true: T) -> When<Self, C, T>where
Self: CaseWhenTypesExtractor<Whens = Whens, Else = E>,
C: Expression,
<C as Expression>::SqlType: BoolOrNullableBool,
T: AsExpression<<Self as CaseWhenTypesExtractor>::OutputExpressionSpecifiedSqlType>,
Add an additional WHEN ... THEN ...
branch to the CASE
expression
See the case_when
documentation for more details.
source§impl<Whens> CaseWhen<Whens, NoElseExpression>
impl<Whens> CaseWhen<Whens, NoElseExpression>
sourcepub fn otherwise<E>(self, if_no_other_branch_matched: E) -> Otherwise<Self, E>where
Self: CaseWhenTypesExtractor<Whens = Whens, Else = NoElseExpression>,
E: AsExpression<<Self as CaseWhenTypesExtractor>::OutputExpressionSpecifiedSqlType>,
pub fn otherwise<E>(self, if_no_other_branch_matched: E) -> Otherwise<Self, E>where
Self: CaseWhenTypesExtractor<Whens = Whens, Else = NoElseExpression>,
E: AsExpression<<Self as CaseWhenTypesExtractor>::OutputExpressionSpecifiedSqlType>,
Sets the ELSE
branch of the CASE
expression
It is named this way because else
is a reserved keyword in Rust
See the case_when
documentation for more details.
Trait Implementations§
source§impl<Whens, E, __Rhs> Add<__Rhs> for CaseWhen<Whens, E>where
Self: Expression,
<Self as Expression>::SqlType: Add,
<<Self as Expression>::SqlType as Add>::Rhs: SqlType + SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Add>::Rhs>,
impl<Whens, E, __Rhs> Add<__Rhs> for CaseWhen<Whens, E>where
Self: Expression,
<Self as Expression>::SqlType: Add,
<<Self as Expression>::SqlType as Add>::Rhs: SqlType + SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Add>::Rhs>,
source§impl<Whens, E, __Rhs> Div<__Rhs> for CaseWhen<Whens, E>where
Self: Expression,
<Self as Expression>::SqlType: Div,
<<Self as Expression>::SqlType as Div>::Rhs: SqlType + SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Div>::Rhs>,
impl<Whens, E, __Rhs> Div<__Rhs> for CaseWhen<Whens, E>where
Self: Expression,
<Self as Expression>::SqlType: Div,
<<Self as Expression>::SqlType as Div>::Rhs: SqlType + SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Div>::Rhs>,
source§impl<W, T, Whens, E> Expression for CaseWhen<CaseWhenConditionsIntermediateNode<W, T, Whens>, E>where
CaseWhen<CaseWhenConditionsLeaf<W, T>, E>: Expression,
CaseWhen<Whens, E>: Expression<SqlType = <CaseWhen<CaseWhenConditionsLeaf<W, T>, E> as Expression>::SqlType>,
impl<W, T, Whens, E> Expression for CaseWhen<CaseWhenConditionsIntermediateNode<W, T, Whens>, E>where
CaseWhen<CaseWhenConditionsLeaf<W, T>, E>: Expression,
CaseWhen<Whens, E>: Expression<SqlType = <CaseWhen<CaseWhenConditionsLeaf<W, T>, E> as Expression>::SqlType>,
source§impl<W, T, E> Expression for CaseWhen<CaseWhenConditionsLeaf<W, T>, ElseExpression<E>>
impl<W, T, E> Expression for CaseWhen<CaseWhenConditionsLeaf<W, T>, ElseExpression<E>>
source§type SqlType = <T as Expression>::SqlType
type SqlType = <T as Expression>::SqlType
The type that this expression represents in SQL
source§impl<W, T> Expression for CaseWhen<CaseWhenConditionsLeaf<W, T>, NoElseExpression>where
W: Expression,
<W as Expression>::SqlType: BoolOrNullableBool,
T: Expression,
<T as Expression>::SqlType: IntoNullable,
<<T as Expression>::SqlType as IntoNullable>::Nullable: SqlType + TypedExpressionType,
impl<W, T> Expression for CaseWhen<CaseWhenConditionsLeaf<W, T>, NoElseExpression>where
W: Expression,
<W as Expression>::SqlType: BoolOrNullableBool,
T: Expression,
<T as Expression>::SqlType: IntoNullable,
<<T as Expression>::SqlType as IntoNullable>::Nullable: SqlType + TypedExpressionType,
source§type SqlType = <<T as Expression>::SqlType as IntoNullable>::Nullable
type SqlType = <<T as Expression>::SqlType as IntoNullable>::Nullable
The type that this expression represents in SQL
source§impl<Whens, E, __Rhs> Mul<__Rhs> for CaseWhen<Whens, E>where
Self: Expression,
<Self as Expression>::SqlType: Mul,
<<Self as Expression>::SqlType as Mul>::Rhs: SqlType + SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Mul>::Rhs>,
impl<Whens, E, __Rhs> Mul<__Rhs> for CaseWhen<Whens, E>where
Self: Expression,
<Self as Expression>::SqlType: Mul,
<<Self as Expression>::SqlType as Mul>::Rhs: SqlType + SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Mul>::Rhs>,
source§impl<Whens, E, DB> QueryFragment<DB> for CaseWhen<Whens, E>
impl<Whens, E, DB> QueryFragment<DB> for CaseWhen<Whens, E>
source§impl<Whens: QueryId, E: QueryId> QueryId for CaseWhen<Whens, E>
impl<Whens: QueryId, E: QueryId> QueryId for CaseWhen<Whens, E>
source§impl<Whens, E, __Rhs> Sub<__Rhs> for CaseWhen<Whens, E>where
Self: Expression,
<Self as Expression>::SqlType: Sub,
<<Self as Expression>::SqlType as Sub>::Rhs: SqlType + SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Sub>::Rhs>,
impl<Whens, E, __Rhs> Sub<__Rhs> for CaseWhen<Whens, E>where
Self: Expression,
<Self as Expression>::SqlType: Sub,
<<Self as Expression>::SqlType as Sub>::Rhs: SqlType + SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Sub>::Rhs>,
source§impl<Whens, E, __GroupByClause> ValidGrouping<__GroupByClause> for CaseWhen<Whens, E>where
Whens: ValidGrouping<__GroupByClause>,
E: ValidGrouping<__GroupByClause>,
Whens::IsAggregate: MixedAggregates<E::IsAggregate>,
impl<Whens, E, __GroupByClause> ValidGrouping<__GroupByClause> for CaseWhen<Whens, E>where
Whens: ValidGrouping<__GroupByClause>,
E: ValidGrouping<__GroupByClause>,
Whens::IsAggregate: MixedAggregates<E::IsAggregate>,
source§type IsAggregate = <<Whens as ValidGrouping<__GroupByClause>>::IsAggregate as MixedAggregates<<E as ValidGrouping<__GroupByClause>>::IsAggregate>>::Output
type IsAggregate = <<Whens as ValidGrouping<__GroupByClause>>::IsAggregate as MixedAggregates<<E as ValidGrouping<__GroupByClause>>::IsAggregate>>::Output
Is this expression aggregate? Read more
impl<W, T, Whens, E, QS> AppearsOnTable<QS> for CaseWhen<CaseWhenConditionsIntermediateNode<W, T, Whens>, E>where
Self: Expression,
W: AppearsOnTable<QS>,
T: AppearsOnTable<QS>,
CaseWhen<Whens, E>: AppearsOnTable<QS>,
impl<W, T, E, QS> AppearsOnTable<QS> for CaseWhen<CaseWhenConditionsLeaf<W, T>, ElseExpression<E>>where
CaseWhen<CaseWhenConditionsLeaf<W, T>, ElseExpression<E>>: Expression,
W: AppearsOnTable<QS>,
T: AppearsOnTable<QS>,
E: AppearsOnTable<QS>,
impl<W, T, QS> AppearsOnTable<QS> for CaseWhen<CaseWhenConditionsLeaf<W, T>, NoElseExpression>where
CaseWhen<CaseWhenConditionsLeaf<W, T>, NoElseExpression>: Expression,
W: AppearsOnTable<QS>,
T: AppearsOnTable<QS>,
impl<Whens: Copy, E: Copy> Copy for CaseWhen<Whens, E>
impl<W, T, Whens, E, QS> SelectableExpression<QS> for CaseWhen<CaseWhenConditionsIntermediateNode<W, T, Whens>, E>where
Self: AppearsOnTable<QS>,
W: SelectableExpression<QS>,
T: SelectableExpression<QS>,
CaseWhen<Whens, E>: SelectableExpression<QS>,
impl<W, T, E, QS> SelectableExpression<QS> for CaseWhen<CaseWhenConditionsLeaf<W, T>, ElseExpression<E>>where
CaseWhen<CaseWhenConditionsLeaf<W, T>, ElseExpression<E>>: AppearsOnTable<QS>,
W: SelectableExpression<QS>,
T: SelectableExpression<QS>,
E: SelectableExpression<QS>,
impl<W, T, QS> SelectableExpression<QS> for CaseWhen<CaseWhenConditionsLeaf<W, T>, NoElseExpression>where
CaseWhen<CaseWhenConditionsLeaf<W, T>, NoElseExpression>: AppearsOnTable<QS>,
W: SelectableExpression<QS>,
T: SelectableExpression<QS>,
Auto Trait Implementations§
impl<Whens, E> Freeze for CaseWhen<Whens, E>
impl<Whens, E> RefUnwindSafe for CaseWhen<Whens, E>where
Whens: RefUnwindSafe,
E: RefUnwindSafe,
impl<Whens, E> Send for CaseWhen<Whens, E>
impl<Whens, E> Sync for CaseWhen<Whens, E>
impl<Whens, E> Unpin for CaseWhen<Whens, E>
impl<Whens, E> UnwindSafe for CaseWhen<Whens, E>where
Whens: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
source§impl<T, ST> AsExpression<ST> for T
impl<T, ST> AsExpression<ST> for T
source§type Expression = T
type Expression = T
The expression being returned
source§fn as_expression(self) -> T
fn as_expression(self) -> T
Perform the conversion
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<Conn, DB, T> ExecuteDsl<Conn, DB> for T
impl<Conn, DB, T> ExecuteDsl<Conn, DB> for T
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§impl<T> NullableExpressionMethods for Twhere
T: Expression,
impl<T> NullableExpressionMethods for Twhere
T: Expression,
source§fn nullable(self) -> Nullable<Self>
fn nullable(self) -> Nullable<Self>
Converts this potentially non-null expression into one which is treated
as nullable. This method has no impact on the generated SQL, and is only
used to allow certain comparisons that would otherwise fail to compile. Read more
source§fn assume_not_null(self) -> AssumeNotNull<Self>
fn assume_not_null(self) -> AssumeNotNull<Self>
Converts this potentially nullable expression into one which will be assumed
to be not-null. This method has no impact on the generated SQL, however it will
enable you to attempt deserialization of the returned value in a non-
Option
. Read more