Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions store/postgres/src/relational_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1618,17 +1618,31 @@ impl<'a> Filter<'a> {
out.push_sql(") > 0");
}
}
SqlValue::List(_) | SqlValue::Numerics(_) => {
if op.negated() {
out.push_sql(" not ");
column.walk_ast(out.reborrow())?;
out.push_sql(" && ");
} else {
SqlValue::List(_) | SqlValue::Numerics(_) => match op {
// For case-insensitive operations
ContainsOp::ILike | ContainsOp::NotILike => {
if op.negated() {
out.push_sql(" not ");
}
out.push_sql("exists (select 1 from unnest(");
column.walk_ast(out.reborrow())?;
out.push_sql(" @> ");
out.push_sql(") as elem where elem ilike any(");
qv.walk_ast(out.reborrow())?;
out.push_sql("))");
}
qv.walk_ast(out)?;
}
_ => {
// For case-sensitive operations
if op.negated() {
out.push_sql(" not ");
column.walk_ast(out.reborrow())?;
out.push_sql(" && ");
} else {
column.walk_ast(out.reborrow())?;
out.push_sql(" @> ");
}
qv.walk_ast(out)?;
}
},
SqlValue::Null
| SqlValue::Bool(_)
| SqlValue::Numeric(_)
Expand Down
25 changes: 25 additions & 0 deletions store/test-store/tests/graphql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2880,6 +2880,31 @@ fn can_query_with_or_explicit_and_filter() {
})
}

#[test]
fn can_query_array_contains_nocase() {
const QUERY: &str = "
query {
musicians(where: { bands_contains_nocase: [\"B1\", \"B2\"] }) {
name
bands { id }
}
}
";

run_query(QUERY, |result, _| {
let exp = object! {
musicians: vec![
object! { name: "John", bands: vec![object! { id: "b1" }, object! { id: "b2" }] },
object! { name: "Lisa", bands: vec![object! { id: "b1" }] },
object! { name: "Tom", bands: vec![object! { id: "b1" }, object! { id: "b2" }] },
object! { name: "Paul", bands: vec![ object! { id: "b2" }] },
],
};
let data = extract_data!(result).unwrap();
assert_eq!(data, exp);
})
}

#[test]
fn can_query_with_or_implicit_and_filter() {
const QUERY: &str = "
Expand Down
Loading