From 016ef912a7587d65161493d9f3ad5732a8c686b0 Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 10 May 2024 12:33:31 -0400 Subject: [PATCH] feat: add In and Like comparison operators to gql --- crates/torii/graphql/src/query/data.rs | 12 ++++++++++++ crates/torii/graphql/src/query/filter.rs | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/crates/torii/graphql/src/query/data.rs b/crates/torii/graphql/src/query/data.rs index f403fc5763..b81ae3b8b4 100644 --- a/crates/torii/graphql/src/query/data.rs +++ b/crates/torii/graphql/src/query/data.rs @@ -227,6 +227,18 @@ fn build_conditions(keys: &Option>, filters: &Option>) - conditions.extend(filters.iter().map(|filter| match &filter.value { FilterValue::Int(i) => format!("{} {} {}", filter.field, filter.comparator, i), FilterValue::String(s) => format!("{} {} '{}'", filter.field, filter.comparator, s), + FilterValue::List(list) => { + let values = list + .iter() + .map(|value| match value { + FilterValue::Int(i) => i.to_string(), + FilterValue::String(s) => format!("'{}'", s), + FilterValue::List(_) => unreachable!(), + }) + .collect::>() + .join(", "); + format!("{} {} ({})", filter.field, filter.comparator, values) + } })); } diff --git a/crates/torii/graphql/src/query/filter.rs b/crates/torii/graphql/src/query/filter.rs index dd6aef3f2e..5fac6626e7 100644 --- a/crates/torii/graphql/src/query/filter.rs +++ b/crates/torii/graphql/src/query/filter.rs @@ -13,6 +13,9 @@ pub enum Comparator { Lte, Neq, Eq, + In, + NotIn, + Like, } impl fmt::Display for Comparator { @@ -24,6 +27,9 @@ impl fmt::Display for Comparator { Comparator::Lte => write!(f, "<="), Comparator::Neq => write!(f, "!="), Comparator::Eq => write!(f, "="), + Comparator::In => write!(f, "IN"), + Comparator::NotIn => write!(f, "NOT IN"), + Comparator::Like => write!(f, "LIKE"), } } } @@ -32,6 +38,7 @@ impl fmt::Display for Comparator { pub enum FilterValue { Int(i64), String(String), + List(Vec), } #[derive(Debug)]