Skip to content

Commit

Permalink
#267 Added is_null and is_not_null
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Oct 23, 2021
1 parent 4913e88 commit 5daa9ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/entity/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ macro_rules! bind_oper {
};
}

macro_rules! bind_agg_func {
macro_rules! bind_func_no_params {
( $func: ident ) => {
/// See also SeaQuery's method with same name.
fn $func(&self) -> SimpleExpr {
Expr::tbl(self.entity_name(), *self).$func()
}
Expand Down Expand Up @@ -213,10 +214,12 @@ pub trait ColumnTrait: IdenStatic + Iterable + FromStr {
Expr::tbl(self.entity_name(), *self).like(&pattern)
}

bind_agg_func!(max);
bind_agg_func!(min);
bind_agg_func!(sum);
bind_agg_func!(count);
bind_func_no_params!(max);
bind_func_no_params!(min);
bind_func_no_params!(sum);
bind_func_no_params!(count);
bind_func_no_params!(is_null);
bind_func_no_params!(is_not_null);

fn if_null<V>(&self, v: V) -> SimpleExpr
where
Expand Down
12 changes: 12 additions & 0 deletions src/query/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,18 @@ pub trait QueryFilter: Sized {
/// r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE (NOT (1 = 1 AND 2 = 2)) AND (3 = 3 OR 4 = 4)"#
/// );
/// ```
/// Use a sea_query expression
/// ```
/// use sea_orm::{entity::*, query::*, sea_query::Expr, tests_cfg::fruit, DbBackend};
///
/// assert_eq!(
/// fruit::Entity::find()
/// .filter(Expr::col(fruit::Column::CakeId).is_null())
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit` WHERE `cake_id` IS NULL"
/// );
/// ```
fn filter<F>(mut self, filter: F) -> Self
where
F: IntoCondition,
Expand Down

0 comments on commit 5daa9ab

Please sign in to comment.