From 6260ec1766f72cfbb8dc02b8f1ca48673f9fea6c Mon Sep 17 00:00:00 2001 From: ljl <17743125563@163.com> Date: Fri, 13 Oct 2023 16:14:44 +0800 Subject: [PATCH] =?UTF-8?q?spi-search:op=20add=20IsNUll=E3=80=81IsNotNUll?= =?UTF-8?q?=E3=80=81IsNullOrEmpty.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basic/src/basic_enumeration.rs | 9 ++++++++ .../src/serv/pg/search_pg_item_serv.rs | 22 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/basic/src/basic_enumeration.rs b/basic/src/basic_enumeration.rs index 0cfd0c312..8f6de704c 100644 --- a/basic/src/basic_enumeration.rs +++ b/basic/src/basic_enumeration.rs @@ -43,6 +43,12 @@ pub enum BasicQueryOpKind { In, #[oai(rename = "not_in")] NotIn, + #[oai(rename = "is_null")] + IsNUll, + #[oai(rename = "is_not_null")] + IsNotNUll, + #[oai(rename = "is_not_null_or_empty")] + IsNullOrEmpty, } impl BasicQueryOpKind { @@ -58,6 +64,9 @@ impl BasicQueryOpKind { BasicQueryOpKind::NotLike => "NOT LIKE".to_string(), BasicQueryOpKind::In => "IN".to_string(), BasicQueryOpKind::NotIn => "NOT IN".to_string(), + BasicQueryOpKind::IsNUll => "IS NULL".to_string(), + BasicQueryOpKind::IsNotNUll => "IS NOT NULL".to_string(), + BasicQueryOpKind::IsNullOrEmpty => "IS NULL".to_string(), } } } diff --git a/spi/spi-search/src/serv/pg/search_pg_item_serv.rs b/spi/spi-search/src/serv/pg/search_pg_item_serv.rs index 32f5c14de..ae2c25d23 100644 --- a/spi/spi-search/src/serv/pg/search_pg_item_serv.rs +++ b/spi/spi-search/src/serv/pg/search_pg_item_serv.rs @@ -307,6 +307,12 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst, for val in value { sql_vals.push(val); } + } else if ext_item.op == BasicQueryOpKind::IsNUll { + where_fragments.push(format!("ext ->> '{}' is null", ext_item.field)); + } else if ext_item.op == BasicQueryOpKind::IsNotNUll { + where_fragments.push(format!("ext ->> '{}' is not null", ext_item.field)); + } else if ext_item.op == BasicQueryOpKind::IsNullOrEmpty { + where_fragments.push(format!("(ext ->> '{}' is null or ext ->> '{}' = '')", ext_item.field, ext_item.field)); } else { if value.len() > 1 { return err_not_found(ext_item); @@ -351,7 +357,7 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst, } } } - + if let Some(sort) = &search_req.sort { for sort_item in sort { if sort_item.field.to_lowercase() == "key" @@ -413,6 +419,12 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst, for val in value { sql_vals.push(val); } + } else if ext_item.op == BasicQueryOpKind::IsNUll { + where_fragments.push(format!("ext ->> '{}' is null", ext_item.field)); + } else if ext_item.op == BasicQueryOpKind::IsNotNUll { + where_fragments.push(format!("ext ->> '{}' is not null", ext_item.field)); + } else if ext_item.op == BasicQueryOpKind::IsNullOrEmpty { + where_fragments.push(format!("(ext ->> '{}' is null or ext ->> '{}' = '')", ext_item.field, ext_item.field)); } else { if value.len() > 1 { return err_not_found(ext_item); @@ -478,7 +490,13 @@ pub async fn search(search_req: &mut SearchItemSearchReq, funs: &TardisFunsInst, sql_vals.push(Value::from(format!("{val}%"))); } } - } else { + }else if ext_item.op == BasicQueryOpKind::IsNUll { + sql_and_where.push(format!("{} is null", ext_item.field)); + } else if ext_item.op == BasicQueryOpKind::IsNotNUll { + sql_and_where.push(format!("{} is not null", ext_item.field)); + } else if ext_item.op == BasicQueryOpKind::IsNullOrEmpty { + sql_and_where.push(format!("({} is null or {} = '')", ext_item.field, ext_item.field)); + } else { if value.len() > 1 { return err_not_found(ext_item); }