Skip to main content

CaseBuilder

Struct CaseBuilder 

Source
pub struct CaseBuilder<'a, V: SQLParam, T: DataType, N: Nullability, A: AggregateKind, S = ()> { /* private fields */ }
Expand description

A CASE builder with at least one branch.

T is the result type set by the first branch and N the nullability of the results so far. S records the tables read so far: WHEN conditions are only scope-checked (a NULL condition falls through to the next branch), while THEN results can make the result NULL.

Implementations§

Source§

impl<'a, V, T, N, A, S> CaseBuilder<'a, V, T, N, A, S>
where V: SQLParam + 'a, T: DataType, N: Nullability, A: AggregateKind,

Source

pub fn when<C, R>( self, condition: C, result: R, ) -> CaseBuilder<'a, V, T, <N as Nullability>::Or<R::Nullable>, <<A as AggregateKind>::Or<C::Aggregate> as AggregateKind>::Or<R::Aggregate>, (S, (ScopeOnly<C::Sources>, R::Sources))>

Adds another WHEN condition THEN result branch.

condition must be boolean and result must have a type compatible with the first branch. The result becomes nullable if this branch’s result is.

Source

pub fn end(self) -> SQLExpr<'a, V, T, Null, A, S>

Finishes the expression without ELSE (... END).

Rows that match no branch give NULL, so the result is always nullable.

§Examples
let label = case().when(users.active, "active").end();
assert_eq!(label.sql(), r#"CASE WHEN "users"."active" THEN ? END"#);
Source

pub fn else<D>( self, default: D, ) -> SQLExpr<'a, V, T, <N as Nullability>::Or<D::Nullable>, <A as AggregateKind>::Or<D::Aggregate>, (S, D::Sources)>

Finishes the expression with a default (... ELSE default END).

default must have a type compatible with the first branch. The result is nullable if any branch result or the default is.

§Examples
let label = case().when(users.active, "active").r#else("inactive");
assert_eq!(label.sql(), r#"CASE WHEN "users"."active" THEN ? ELSE ? END"#);

Auto Trait Implementations§

§

impl<'a, V, T, N, A, S> Freeze for CaseBuilder<'a, V, T, N, A, S>

§

impl<'a, V, T, N, A, S> RefUnwindSafe for CaseBuilder<'a, V, T, N, A, S>

§

impl<'a, V, T, N, A, S> Send for CaseBuilder<'a, V, T, N, A, S>
where SQL<'a, V>: Send, PhantomData<fn() -> (V, T, N, A, S)>: Send,

§

impl<'a, V, T, N, A, S> Sync for CaseBuilder<'a, V, T, N, A, S>
where SQL<'a, V>: Sync, PhantomData<fn() -> (V, T, N, A, S)>: Sync,

§

impl<'a, V, T, N, A, S> Unpin for CaseBuilder<'a, V, T, N, A, S>
where SQL<'a, V>: Unpin, PhantomData<fn() -> (V, T, N, A, S)>: Unpin,

§

impl<'a, V, T, N, A, S> UnsafeUnpin for CaseBuilder<'a, V, T, N, A, S>

§

impl<'a, V, T, N, A, S> UnwindSafe for CaseBuilder<'a, V, T, N, A, S>

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> 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<List> ListIncludes<Nil, ()> for List

Source§

impl<Mk> MarkerAggValidFor<()> for Mk

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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