You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-3.x/orm/api/filter.md
+81Lines changed: 81 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,88 @@ sidebar_position: 3
3
3
description: how to filter entities
4
4
---
5
5
6
+
import GithubCodeBlock from '@site/src/components/GithubCodeBlock';
6
7
import StackBlitzGithubEmbed from '@site/src/components/StackBlitzGithubEmbed';
7
8
8
9
# Filter
9
10
11
+
Filtering is an important topic because it's involved in many ORM operations, for example when you find records, selecting relations, and updating or deleting multiple records.
12
+
13
+
Throughout this section all samples are based on the following ZModel schema:
You can filter on scalar fields with values or operators as supported by the field type. The following filter operators are available.
20
+
21
+
-`equals``not`: all scalar fields.
22
+
-`in``notIn`: all scalar fields
23
+
-`contains``startsWith``endsWith`: String fields
24
+
-`lt``lte``gt``gte`: String, Int, BigInt, Float, Decimal, and Date fields
25
+
26
+
A filter object can contain multiple field filters, and they are combined with `AND` semantic. You can also use the `AND`, `OR`, and `NOT` logical operators to combine filter objects to form a complex filter.
Filters can be defined on conditions over relations. For one-to-one relations, you can filter on their fields directly. For one-to-many relations, use the "some", "every", or "none" operators to build a condition over a list of records.
Filtering on Json fields is work in progress and will be available soon.
82
+
:::
83
+
84
+
## Query builder filters
85
+
86
+
ZenStack v3 is implemented on top of [Kysely](https://kysely.dev/), and it leverages Kysely's powerful query builder API to extend the filtering capabilities. You can use the `$expr` operator to define a boolean expression that can express almost everything that can be expressed in SQL.
87
+
88
+
The `$expr` operator can be used together with other filter operators, so you can keep most of your filters simple and only reach to the query builder level for complicated components.
0 commit comments