Skip to content

Commit d0ae5cb

Browse files
authored
store: handle case insensitive array inputs in query
* store: handle case insensitive array inputs in query * test: add test for case insensitive query
1 parent 6b49d26 commit d0ae5cb

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

store/postgres/src/relational_queries.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,17 +1618,31 @@ impl<'a> Filter<'a> {
16181618
out.push_sql(") > 0");
16191619
}
16201620
}
1621-
SqlValue::List(_) | SqlValue::Numerics(_) => {
1622-
if op.negated() {
1623-
out.push_sql(" not ");
1624-
column.walk_ast(out.reborrow())?;
1625-
out.push_sql(" && ");
1626-
} else {
1621+
SqlValue::List(_) | SqlValue::Numerics(_) => match op {
1622+
// For case-insensitive operations
1623+
ContainsOp::ILike | ContainsOp::NotILike => {
1624+
if op.negated() {
1625+
out.push_sql(" not ");
1626+
}
1627+
out.push_sql("exists (select 1 from unnest(");
16271628
column.walk_ast(out.reborrow())?;
1628-
out.push_sql(" @> ");
1629+
out.push_sql(") as elem where elem ilike any(");
1630+
qv.walk_ast(out.reborrow())?;
1631+
out.push_sql("))");
16291632
}
1630-
qv.walk_ast(out)?;
1631-
}
1633+
_ => {
1634+
// For case-sensitive operations
1635+
if op.negated() {
1636+
out.push_sql(" not ");
1637+
column.walk_ast(out.reborrow())?;
1638+
out.push_sql(" && ");
1639+
} else {
1640+
column.walk_ast(out.reborrow())?;
1641+
out.push_sql(" @> ");
1642+
}
1643+
qv.walk_ast(out)?;
1644+
}
1645+
},
16321646
SqlValue::Null
16331647
| SqlValue::Bool(_)
16341648
| SqlValue::Numeric(_)

store/test-store/tests/graphql/query.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,31 @@ fn can_query_with_or_explicit_and_filter() {
28802880
})
28812881
}
28822882

2883+
#[test]
2884+
fn can_query_array_contains_nocase() {
2885+
const QUERY: &str = "
2886+
query {
2887+
musicians(where: { bands_contains_nocase: [\"B1\", \"B2\"] }) {
2888+
name
2889+
bands { id }
2890+
}
2891+
}
2892+
";
2893+
2894+
run_query(QUERY, |result, _| {
2895+
let exp = object! {
2896+
musicians: vec![
2897+
object! { name: "John", bands: vec![object! { id: "b1" }, object! { id: "b2" }] },
2898+
object! { name: "Lisa", bands: vec![object! { id: "b1" }] },
2899+
object! { name: "Tom", bands: vec![object! { id: "b1" }, object! { id: "b2" }] },
2900+
object! { name: "Paul", bands: vec![ object! { id: "b2" }] },
2901+
],
2902+
};
2903+
let data = extract_data!(result).unwrap();
2904+
assert_eq!(data, exp);
2905+
})
2906+
}
2907+
28832908
#[test]
28842909
fn can_query_with_or_implicit_and_filter() {
28852910
const QUERY: &str = "

0 commit comments

Comments
 (0)