pub struct CaseStatement { /* private fields */ }
Implementationsยง
sourceยงimpl CaseStatement
impl CaseStatement
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new case statement expression
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr_as(
CaseStatement::new()
.case(Expr::col((Glyph::Table, Glyph::Aspect)).is_in([2, 4]), true)
.finally(false),
Alias::new("is_even")
)
.from(Glyph::Table)
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT (CASE WHEN ("glyph"."aspect" IN (2, 4)) THEN TRUE ELSE FALSE END) AS "is_even" FROM "glyph""#
);
sourcepub fn case<C, T>(self, cond: C, then: T) -> Self
pub fn case<C, T>(self, cond: C, then: T) -> Self
Adds new CASE WHEN
to existing case statement.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr_as(
Expr::case(
Expr::col((Glyph::Table, Glyph::Aspect)).gt(0),
"positive"
)
.case(
Expr::col((Glyph::Table, Glyph::Aspect)).lt(0),
"negative"
)
.finally("zero"),
Alias::new("polarity")
)
.from(Glyph::Table)
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT (CASE WHEN ("glyph"."aspect" > 0) THEN 'positive' WHEN ("glyph"."aspect" < 0) THEN 'negative' ELSE 'zero' END) AS "polarity" FROM "glyph""#
);
sourcepub fn finally<E>(self, else: E) -> Selfwhere
E: Into<SimpleExpr>,
pub fn finally<E>(self, else: E) -> Selfwhere
E: Into<SimpleExpr>,
Ends the case statement with the final ELSE
result.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr_as(
Expr::case(
Cond::any()
.add(Expr::col((Character::Table, Character::FontSize)).gt(48))
.add(Expr::col((Character::Table, Character::SizeW)).gt(500)),
"large"
)
.case(
Cond::any()
.add(Expr::col((Character::Table, Character::FontSize)).between(24,48))
.add(Expr::col((Character::Table, Character::SizeW)).between(300,500)),
"medium"
)
.finally("small"),
Alias::new("char_size"))
.from(Character::Table)
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
[
r#"SELECT"#,
r#"(CASE WHEN ("character"."font_size" > 48 OR "character"."size_w" > 500) THEN 'large'"#,
r#"WHEN (("character"."font_size" BETWEEN 24 AND 48) OR ("character"."size_w" BETWEEN 300 AND 500)) THEN 'medium'"#,
r#"ELSE 'small' END) AS "char_size""#,
r#"FROM "character""#
]
.join(" ")
);
Trait Implementationsยง
sourceยงimpl Clone for CaseStatement
impl Clone for CaseStatement
sourceยงfn clone(&self) -> CaseStatement
fn clone(&self) -> CaseStatement
Returns a copy of the value. Read more
1.0.0 ยท sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceยงimpl Debug for CaseStatement
impl Debug for CaseStatement
sourceยงimpl Default for CaseStatement
impl Default for CaseStatement
sourceยงfn default() -> CaseStatement
fn default() -> CaseStatement
Returns the โdefault valueโ for a type. Read more
sourceยงimpl Into<SimpleExpr> for CaseStatement
impl Into<SimpleExpr> for CaseStatement
sourceยงfn into(self) -> SimpleExpr
fn into(self) -> SimpleExpr
Converts this type into the (usually inferred) input type.
sourceยงimpl PartialEq for CaseStatement
impl PartialEq for CaseStatement
impl StructuralPartialEq for CaseStatement
Auto Trait Implementationsยง
impl Freeze for CaseStatement
impl !RefUnwindSafe for CaseStatement
impl Send for CaseStatement
impl Sync for CaseStatement
impl Unpin for CaseStatement
impl !UnwindSafe for CaseStatement
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
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<T> ExprTrait for Twhere
T: Into<SimpleExpr>,
impl<T> ExprTrait for Twhere
T: Into<SimpleExpr>,
sourceยงfn as_enum<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
fn as_enum<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
Express a
AS enum
expression. Read moresourceยงfn binary<O, R>(self, op: O, right: R) -> SimpleExpr
fn binary<O, R>(self, op: O, right: R) -> SimpleExpr
Create any binary operation Read more
sourceยงfn cast_as<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
fn cast_as<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
Express a
CAST AS
expression. Read moresourceยงfn unary(self, op: UnOper) -> SimpleExpr
fn unary(self, op: UnOper) -> SimpleExpr
Apply any unary operator to the expression. Read more
sourceยงfn add<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn add<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic addition operation. Read more
fn and<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
sourceยงfn between<A, B>(self, a: A, b: B) -> SimpleExpr
fn between<A, B>(self, a: A, b: B) -> SimpleExpr
Express a
BETWEEN
expression. Read moresourceยงfn div<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn div<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic division operation. Read more
sourceยงfn eq<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn eq<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an equal (
=
) expression. Read moresourceยงfn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
fn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
Express a equal expression between two table columns,
you will mainly use this to relate identical value between two table columns. Read more
sourceยงfn gt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn gt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a greater than (
>
) expression. Read moresourceยงfn gte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn gte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a greater than or equal (
>=
) expression. Read moresourceยงfn in_subquery(self, sel: SelectStatement) -> SimpleExpr
fn in_subquery(self, sel: SelectStatement) -> SimpleExpr
Express a
IN
sub-query expression. Read moresourceยงfn in_tuples<V, I>(self, v: I) -> SimpleExprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
fn in_tuples<V, I>(self, v: I) -> SimpleExprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
Express a
IN
sub expression. Read moresourceยงfn is<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn is<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a
IS
expression. Read moresourceยงfn is_in<V, I>(self, v: I) -> SimpleExpr
fn is_in<V, I>(self, v: I) -> SimpleExpr
Express a
IN
expression. Read moresourceยงfn is_not<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn is_not<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a
IS NOT
expression. Read moresourceยงfn is_not_in<V, I>(self, v: I) -> SimpleExpr
fn is_not_in<V, I>(self, v: I) -> SimpleExpr
Express a
NOT IN
expression. Read moresourceยงfn is_not_null(self) -> SimpleExpr
fn is_not_null(self) -> SimpleExpr
Express a
IS NOT NULL
expression. Read moresourceยงfn is_null(self) -> SimpleExpr
fn is_null(self) -> SimpleExpr
Express a
IS NULL
expression. Read moresourceยงfn left_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn left_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a bitwise left shift. Read more
sourceยงfn like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
Express a
LIKE
expression. Read moresourceยงfn lt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn lt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a less than (
<
) expression. Read moresourceยงfn lte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn lte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a less than or equal (
<=
) expression. Read moresourceยงfn modulo<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn modulo<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic modulo operation. Read more
sourceยงfn mul<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn mul<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic multiplication operation. Read more
sourceยงfn ne<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn ne<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a not equal (
<>
) expression. Read moresourceยงfn not(self) -> SimpleExpr
fn not(self) -> SimpleExpr
Negates an expression with
NOT
. Read moresourceยงfn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
fn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
Express a
NOT BETWEEN
expression. Read moresourceยงfn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
fn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
Express a not equal expression between two table columns,
you will mainly use this to relate identical value between two table columns. Read more
sourceยงfn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
Express a
NOT IN
sub-query expression. Read moresourceยงfn not_like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn not_like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
Express a
NOT LIKE
expression. Read moresourceยงfn or<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn or<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a logical
OR
operation. Read moresourceยงfn right_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn right_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a bitwise right shift. Read more
sourceยงfn sub<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn sub<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic subtraction operation. Read more