Skip to content

Commit

Permalink
feat: add In and Like comparison operators to gql
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed May 10, 2024
1 parent 6dca944 commit 016ef91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/torii/graphql/src/query/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ fn build_conditions(keys: &Option<Vec<String>>, filters: &Option<Vec<Filter>>) -
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::<Vec<_>>()
.join(", ");
format!("{} {} ({})", filter.field, filter.comparator, values)
}
}));
}

Expand Down
7 changes: 7 additions & 0 deletions crates/torii/graphql/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub enum Comparator {
Lte,
Neq,
Eq,
In,
NotIn,
Like,
}

impl fmt::Display for Comparator {
Expand All @@ -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"),
}
}
}
Expand All @@ -32,6 +38,7 @@ impl fmt::Display for Comparator {
pub enum FilterValue {
Int(i64),
String(String),
List(Vec<FilterValue>),
}

#[derive(Debug)]
Expand Down

0 comments on commit 016ef91

Please sign in to comment.