From e216974fa3372a6166f99004eb9de002bf516e40 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Tue, 25 May 2021 22:30:17 +0800 Subject: [PATCH] sea_query IntoCondition --- src/entity/base.rs | 2 +- src/query/combine.rs | 2 +- src/query/helper.rs | 26 ++++++-------------------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/entity/base.rs b/src/entity/base.rs index 84a11ea2..4283a27f 100644 --- a/src/entity/base.rs +++ b/src/entity/base.rs @@ -70,7 +70,7 @@ pub trait EntityTrait: EntityName { /// .to_string(), /// [ /// r#"SELECT "cake_filling"."cake_id", "cake_filling"."filling_id" FROM "cake_filling""#, - /// r#"WHERE "cake_filling"."cake_id" = 2 AND ("cake_filling"."filling_id" = 3)"#, + /// r#"WHERE "cake_filling"."cake_id" = 2 AND "cake_filling"."filling_id" = 3"#, /// ].join(" ") /// ); /// ``` diff --git a/src/query/combine.rs b/src/query/combine.rs index 8de78c1f..757fa3ee 100644 --- a/src/query/combine.rs +++ b/src/query/combine.rs @@ -116,7 +116,7 @@ mod tests { "SELECT `cake`.`id` AS `A_id`, `cake`.`name` AS `A_name`,", "`fruit`.`id` AS `B_id`, `fruit`.`name` AS `B_name`, `fruit`.`cake_id` AS `B_cake_id`", "FROM `cake` LEFT JOIN `fruit` ON `cake`.`id` = `fruit`.`cake_id`", - "WHERE `cake`.`id` = 1 AND (`fruit`.`id` = 2)", + "WHERE `cake`.`id` = 1 AND `fruit`.`id` = 2", ].join(" ") ); } diff --git a/src/query/helper.rs b/src/query/helper.rs index ccc38dfb..d973fe6e 100644 --- a/src/query/helper.rs +++ b/src/query/helper.rs @@ -1,12 +1,8 @@ use crate::{ColumnTrait, Identity, IntoSimpleExpr, RelationDef}; -use sea_query::{Alias, Expr, SelectExpr, SelectStatement, SimpleExpr}; +use sea_query::{Alias, Expr, IntoCondition, SelectExpr, SelectStatement, SimpleExpr}; pub use sea_query::{Condition, JoinType, Order}; use std::rc::Rc; -pub trait IntoCondition { - fn into_condition(self) -> Condition; -} - pub trait QueryHelper: Sized { fn query(&mut self) -> &mut SelectStatement; @@ -71,10 +67,10 @@ pub trait QueryHelper: Sized { /// .filter(cake::Column::Id.eq(5)) /// .build(MysqlQueryBuilder) /// .to_string(), - /// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = 4 AND (`cake`.`id` = 5)" + /// "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` = 4 AND `cake`.`id` = 5" /// ); /// ``` - /// + /// /// Add a condition tree. /// ``` /// use sea_orm::{Condition, ColumnTrait, EntityTrait, QueryHelper, tests_cfg::cake, sea_query::MysqlQueryBuilder}; @@ -92,7 +88,9 @@ pub trait QueryHelper: Sized { /// ); /// ``` fn filter(mut self, filter: F) -> Self - where F: IntoCondition { + where + F: IntoCondition, + { self.query().cond_where(filter.into_condition()); self } @@ -216,18 +214,6 @@ pub trait QueryHelper: Sized { } } -impl IntoCondition for SimpleExpr { - fn into_condition(self) -> Condition { - Condition::all().add(self) - } -} - -impl IntoCondition for Condition { - fn into_condition(self) -> Condition { - self - } -} - fn join_condition(rel: RelationDef) -> SimpleExpr { let from_tbl = rel.from_tbl.clone(); let to_tbl = rel.to_tbl.clone();