Skip to content

Commit

Permalink
Only eq & ne operators with enum casting
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Nov 5, 2021
1 parent 67bb168 commit 10f3de0
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ pub enum ColumnType {
}

macro_rules! bind_oper {
( $op: ident ) => {
#[allow(missing_docs)]
fn $op<V>(&self, v: V) -> SimpleExpr
where
V: Into<Value>,
{
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<V>(&self, v: V) -> SimpleExpr
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 10f3de0

Please sign in to comment.