Filtering
Gybson has a comprehensive type-safe filtering API so that you can access the exact data you need.
Supported filters
Conditions
Rows can be filtered by a range of conditions. The conditions are slightly different depending on the column type. The supported conditions are:
equals
- The column equals the value (the default)not
- The column does not equal the valuein
- The column is in a list of valuesnotIn
- The column is not in a list of valueslt
- The column is less than the valuelte
- The column is less or equal to the valuegt
- The column is greater than the valuegte
- The column is greater than or equal to the value
String type columns only
contains
- The column is contains the substringstartsWith
- The column is starts with the substringendsWith
- The column ends with the substring
e.g. All users named 'Steve' who are more than 20 years old
Gates (combiners)
Clauses can be joined using AND, OR and NOT
AND
- All conditions are true (the default)OR
- At least one condition is trueNOT
- None of the conditions are true
e.g. All users named 'Steve' who are 20 or 30 years old
Relation filters
Related tables can be filtered by different options depending on the relationship cardinality (1-N, N-1, N-N, 1-1)
The relation filters available are:
exists
- boolean - assert whether there is/is not at least one related rowwhere
- there is at least one related row that matches the conditionwhereEvery
- every related row matches the condition
e.g.
All users who have a post with a rating above 4
All users who have not made any posts
Complex filtering example with findMany
Find the first 3 users where:
- The city is 'NY'
- The last name does NOT start with 'P',
- The age is less than 20
- The favourite Pet is either a 'dog' or a 'cat'
- Every pet they own is a dog
- Every dog they own has toy
Generated types
Types are generated to match the filtering options available.
Example schema
Types
Here are some examples of the types generated for the above schema:
Prior art
The gybson filtering API was inspired by Prisma. See comparisons for an in depth comparison.