Skip to content

Commit

Permalink
spi-search:op add IsNUll、IsNotNUll、IsNullOrEmpty.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Oct 13, 2023
1 parent 95e10c7 commit 6260ec1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
9 changes: 9 additions & 0 deletions basic/src/basic_enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
}
22 changes: 20 additions & 2 deletions spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6260ec1

Please sign in to comment.