Skip to content

Commit

Permalink
Merge pull request #364 from dojoengine/fix/in-operator
Browse files Browse the repository at this point in the history
fix: support in operator
  • Loading branch information
MartianGreed authored Jan 1, 2025
2 parents 33821e5 + b9cb6be commit 58ccba5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/sdk/src/convertQuerytoClause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ function convertOperator(operator: string): torii.ComparisonOperator {
return "Lt";
case "$lte":
return "Lte";
case "$in":
return "In";
case "$nin":
return "NotIn";
default:
throw new Error(`Unsupported operator: ${operator}`);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/sdk/src/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ class QueryEntity<T extends SchemaType> {
return this.addConstraint(field, value, Operator.lte);
}

public in(
field: FirstLevelKeys<T[keyof T & string][keyof T[keyof T & string]]>,
value: any
): QueryEntity<T> {
return this.addConstraint(field, value, Operator.in);
}

public notIn(
field: FirstLevelKeys<T[keyof T & string][keyof T[keyof T & string]]>,
value: any
): QueryEntity<T> {
return this.addConstraint(field, value, Operator.nin);
}

private addConstraint(
field: FirstLevelKeys<T[keyof T & string][keyof T[keyof T & string]]>,
value: any,
Expand Down Expand Up @@ -177,4 +191,6 @@ enum Operator {
gte = "$gte",
lt = "$lt",
lte = "$lte",
in = "$in",
nin = "$nin",
}

0 comments on commit 58ccba5

Please sign in to comment.