Trait sea_query::query::ConditionalStatement [−][src]
pub trait ConditionalStatement { fn cond_where<C>(&mut self, condition: C) -> &mut Self
where
C: IntoCondition; fn and_where(&mut self, other: SimpleExpr) -> &mut Self { ... } fn and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self { ... } fn or_where(&mut self, other: SimpleExpr) -> &mut Self { ... } }
Required methods
fn cond_where<C>(&mut self, condition: C) -> &mut Self where
C: IntoCondition,
[src]
fn cond_where<C>(&mut self, condition: C) -> &mut Self where
C: IntoCondition,
[src]Where condition, expressed with any
and all
.
This cannot be mixed with ConditionalStatement::and_where
.
Calling cond_where
after and_where
will panic.
Calling cond_where
multiple times will conjoin them.
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::select() .column(Glyph::Image) .from(Glyph::Table) .cond_where( Cond::all() .add(Expr::tbl(Glyph::Table, Glyph::Aspect).is_in(vec![3, 4])) .add(Cond::any() .add(Expr::tbl(Glyph::Table, Glyph::Image).like("A%")) .add(Expr::tbl(Glyph::Table, Glyph::Image).like("B%")) ) ) .to_owned(); assert_eq!( query.to_string(PostgresQueryBuilder), r#"SELECT "image" FROM "glyph" WHERE "glyph"."aspect" IN (3, 4) AND ("glyph"."image" LIKE 'A%' OR "glyph"."image" LIKE 'B%')"# );
Using macro
use sea_query::{*, tests_cfg::*}; let query = Query::select() .column(Glyph::Image) .from(Glyph::Table) .cond_where( all![ Expr::tbl(Glyph::Table, Glyph::Aspect).is_in(vec![3, 4]), any![ Expr::tbl(Glyph::Table, Glyph::Image).like("A%"), Expr::tbl(Glyph::Table, Glyph::Image).like("B%") ] ]) .to_owned(); assert_eq!( query.to_string(PostgresQueryBuilder), r#"SELECT "image" FROM "glyph" WHERE "glyph"."aspect" IN (3, 4) AND ("glyph"."image" LIKE 'A%' OR "glyph"."image" LIKE 'B%')"# );
Calling multiple times
use sea_query::{*, tests_cfg::*}; assert_eq!( Query::select() .cond_where(Cond::all().add(Expr::col(Glyph::Id).eq(1))) .cond_where( Cond::any() .add(Expr::col(Glyph::Id).eq(2)) .add(Expr::col(Glyph::Id).eq(3)), ) .to_owned() .to_string(PostgresQueryBuilder), r#"SELECT WHERE "id" = 1 AND ("id" = 2 OR "id" = 3)"# );
Calling multiple times
use sea_query::{*, tests_cfg::*}; assert_eq!( Query::select() .cond_where( Cond::any() .add(Expr::col(Glyph::Id).eq(1)) .add(Expr::col(Glyph::Id).eq(2)), ) .cond_where(Expr::col(Glyph::Id).eq(3)) .cond_where(Expr::col(Glyph::Id).eq(4)) .to_owned() .to_string(PostgresQueryBuilder), r#"SELECT WHERE "id" = 1 OR "id" = 2 OR "id" = 3 OR "id" = 4"# );
Provided methods
fn and_where(&mut self, other: SimpleExpr) -> &mut Self
[src]
fn and_where(&mut self, other: SimpleExpr) -> &mut Self
[src]And where condition. This cannot be mixed with ConditionalStatement::or_where
.
Calling or_where
after and_where
will panic.
Examples
use sea_query::{*, tests_cfg::*}; let query = Query::select() .column(Glyph::Image) .from(Glyph::Table) .and_where(Expr::tbl(Glyph::Table, Glyph::Aspect).is_in(vec![3, 4])) .and_where(Expr::tbl(Glyph::Table, Glyph::Image).like("A%")) .to_owned(); assert_eq!( query.to_string(MysqlQueryBuilder), r#"SELECT `image` FROM `glyph` WHERE `glyph`.`aspect` IN (3, 4) AND `glyph`.`image` LIKE 'A%'"# );
fn and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
[src]
fn and_where_option(&mut self, other: Option<SimpleExpr>) -> &mut Self
[src]And where condition, short hand for if c.is_some() q.and_where(c)
.
fn or_where(&mut self, other: SimpleExpr) -> &mut Self
[src]
fn or_where(&mut self, other: SimpleExpr) -> &mut Self
[src]๐ Deprecated since 0.12.0:
Please use [ConditionalStatement::cond_where
]. Calling or_where
after and_where
will panic.
Implementors
impl ConditionalStatement for DeleteStatement
[src]
impl ConditionalStatement for DeleteStatement
[src]fn and_or_where(&mut self, condition: LogicalChainOper) -> &mut Self
[src]
fn cond_where<C>(&mut self, condition: C) -> &mut Self where
C: IntoCondition,
[src]
C: IntoCondition,
impl ConditionalStatement for SelectStatement
[src]
impl ConditionalStatement for SelectStatement
[src]fn and_or_where(&mut self, condition: LogicalChainOper) -> &mut Self
[src]
fn cond_where<C>(&mut self, condition: C) -> &mut Self where
C: IntoCondition,
[src]
C: IntoCondition,
impl ConditionalStatement for UpdateStatement
[src]
impl ConditionalStatement for UpdateStatement
[src]fn and_or_where(&mut self, condition: LogicalChainOper) -> &mut Self
[src]
fn cond_where<C>(&mut self, condition: C) -> &mut Self where
C: IntoCondition,
[src]
C: IntoCondition,