From 10f3de0f9da0738903c6cb962d11e371f1d2f278 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Fri, 5 Nov 2021 11:13:31 +0800 Subject: [PATCH] Only `eq` & `ne` operators with enum casting --- src/entity/column.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/entity/column.rs b/src/entity/column.rs index d1910f1d..fdb7d486 100644 --- a/src/entity/column.rs +++ b/src/entity/column.rs @@ -67,6 +67,18 @@ pub enum ColumnType { } macro_rules! bind_oper { + ( $op: ident ) => { + #[allow(missing_docs)] + fn $op(&self, v: V) -> SimpleExpr + where + V: Into, + { + Expr::tbl(self.entity_name(), *self).$op(v) + } + }; +} + +macro_rules! bind_oper_with_enum_casting { ( $op: ident, $bin_op: ident ) => { #[allow(missing_docs)] fn $op(&self, v: V) -> SimpleExpr @@ -135,12 +147,12 @@ pub trait ColumnTrait: IdenStatic + Iterable + FromStr { (self.entity_name(), SeaRc::new(*self) as DynIden) } - bind_oper!(eq, Equal); - bind_oper!(ne, NotEqual); - bind_oper!(gt, GreaterThan); - bind_oper!(gte, GreaterThanOrEqual); - bind_oper!(lt, SmallerThan); - bind_oper!(lte, SmallerThanOrEqual); + bind_oper_with_enum_casting!(eq, Equal); + bind_oper_with_enum_casting!(ne, NotEqual); + bind_oper!(gt); + bind_oper!(gte); + bind_oper!(lt); + bind_oper!(lte); /// ``` /// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};