#267 Added is_null and is_not_null

This commit is contained in:
Chris Tsang 2021-10-23 15:41:16 +08:00
parent 4913e88f3a
commit 5daa9abd38
2 changed files with 20 additions and 5 deletions

View File

@ -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()
}
@ -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

View File

@ -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,