pub struct CaseExpression { /* private fields */ }Expand description
A CASE expression: WHEN clauses in order, an optional ELSE and an alias.
PHP: Utopia\Query\Builder\Case\Expression.
use utopia_query::builder::{CaseExpression, MySql, Operator};
let mut case = CaseExpression::new();
case.when("status", Operator::Equal, "active", 1).else_(0).alias("is_active");
let statement = MySql::new().from("users", "").select_case(case).build()?;
assert_eq!(statement.query, "SELECT CASE WHEN `status` = ? THEN ? ELSE ? END AS `is_active` FROM `users`");use Utopia\Query\Builder\Case\Expression;
use Utopia\Query\Builder\Case\Operator;
use Utopia\Query\Builder\MySQL;
$case = (new Expression())->when('status', Operator::Equal, 'active', 1)->else(0)->alias('is_active');
echo (new MySQL())->from('users')->selectCase($case)->build()->query, "\n";Implementations§
Source§impl CaseExpression
impl CaseExpression
Sourcepub fn when(
&mut self,
column: impl Into<String>,
operator: Operator,
value: impl IntoValue,
then: impl IntoValue,
) -> &mut Self
pub fn when( &mut self, column: impl Into<String>, operator: Operator, value: impl IntoValue, then: impl IntoValue, ) -> &mut Self
WHEN column operator value THEN then.
PHP: when().
Sourcepub fn when_null(
&mut self,
column: impl Into<String>,
then: impl IntoValue,
) -> &mut Self
pub fn when_null( &mut self, column: impl Into<String>, then: impl IntoValue, ) -> &mut Self
WHEN column IS NULL THEN then.
PHP: whenNull().
Sourcepub fn when_not_null(
&mut self,
column: impl Into<String>,
then: impl IntoValue,
) -> &mut Self
pub fn when_not_null( &mut self, column: impl Into<String>, then: impl IntoValue, ) -> &mut Self
WHEN column IS NOT NULL THEN then.
PHP: whenNotNull().
Sourcepub fn when_in(
&mut self,
column: impl Into<String>,
values: impl IntoValues,
then: impl IntoValue,
) -> Result<&mut Self>
pub fn when_in( &mut self, column: impl Into<String>, values: impl IntoValues, then: impl IntoValue, ) -> Result<&mut Self>
WHEN column IN (values) THEN then; values must not be empty.
PHP: whenIn().
Sourcepub fn when_raw(
&mut self,
condition: impl Into<String>,
then: impl IntoValue,
bindings: impl IntoValues,
) -> &mut Self
pub fn when_raw( &mut self, condition: impl Into<String>, then: impl IntoValue, bindings: impl IntoValues, ) -> &mut Self
WHEN condition THEN then with raw SQL and its bindings.
PHP: whenRaw().
Sourcepub fn alias(&mut self, alias: impl Into<String>) -> &mut Self
pub fn alias(&mut self, alias: impl Into<String>) -> &mut Self
The alias (AS alias).
PHP: alias().
Sourcepub fn whens(&self) -> &[WhenClause]
pub fn whens(&self) -> &[WhenClause]
The WHEN clauses.
PHP: getWhens().
Sourcepub fn else_value(&self) -> &Value
pub fn else_value(&self) -> &Value
The ELSE value (null when none).
PHP: getElse().
Trait Implementations§
Source§impl Clone for CaseExpression
impl Clone for CaseExpression
Source§impl Debug for CaseExpression
impl Debug for CaseExpression
Source§impl Default for CaseExpression
impl Default for CaseExpression
Source§impl PartialEq for CaseExpression
impl PartialEq for CaseExpression
impl StructuralPartialEq for CaseExpression
Auto Trait Implementations§
impl !Freeze for CaseExpression
impl Forget for CaseExpression
impl Move for CaseExpression
impl RefUnwindSafe for CaseExpressionwhere
Atomic<*mut ()>: RefUnwindSafe,
Atomic<usize>: RefUnwindSafe,
OnceLock<Index>: RefUnwindSafe,
Atomic<u8>: RefUnwindSafe,
impl Send for CaseExpression
impl Sync for CaseExpression
impl Unpin for CaseExpression
impl UnsafeUnpin for CaseExpressionwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<WhenClause>: UnsafeUnpin,
&'static [u8]: UnsafeUnpin,
*const u8: UnsafeUnpin,
Align8<*mut ()>: UnsafeUnpin,
&'static Vtable: UnsafeUnpin,
*const ArcInner<Repr<Object>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Repr<Object>>>: UnsafeUnpin,
*const Query is !null: UnsafeUnpin,
PhantomData<Query>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
impl UnwindSafe for CaseExpressionwhere
RawVecInner: UnwindSafe,
&'static [u8]: UnwindSafe,
*const u8: UnwindSafe,
Align8<*mut ()>: UnwindSafe,
&'static Vtable: UnwindSafe,
Arc<Repr<Object>>: UnwindSafe,
BoxRaw<Query>: UnwindSafe,
Blanket Implementations§
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