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: usage/sync-rules/parameter-queries.mdx
+12-2Lines changed: 12 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,14 +7,14 @@ Parameter queries allow parameters to be defined on a bucket to group data. Thes
7
7
```yaml
8
8
bucket_definitions:
9
9
# Bucket Name
10
-
user_buckets:
10
+
user_lists:
11
11
# Parameter Query
12
12
parameters: SELECT request.user_id() as user_id
13
13
# Data Query
14
14
data:
15
15
- SELECT * FROM lists WHERE lists.owner_id = bucket.user_id
16
16
17
-
user_table_buckets:
17
+
user_lists_table:
18
18
# Similar query, but using a table
19
19
# Access can instantly be revoked by deleting the user row/document
20
20
parameters: SELECT id as user_id FROM users WHERE users.id = request.user_id()
@@ -25,7 +25,9 @@ bucket_definitions:
25
25
Available functions in sync rules are:
26
26
27
27
1. `request.user_id()`: Returns the JWT subject, same as `request.jwt() ->> 'sub'`
28
+
28
29
2. `request.jwt()`: Returns the entire (signed) JWT payload as a JSON string.
30
+
29
31
3. `request.parameters()`: Returns [client parameters](/usage/sync-rules/advanced-topics/client-parameters) as a JSON string.
30
32
31
33
Example usage:
@@ -63,16 +65,21 @@ request.jwt() ->> 'app_metadata.custom_field' -- custom field added by a service
63
65
The new functions available in sync rules are:
64
66
65
67
1. `request.jwt()`: Returns the entire (signed) JWT payload as a JSON string.
68
+
66
69
2. `request.parameters()`: Returns [client parameters](/usage/sync-rules/advanced-topics/client-parameters) as a JSON string.
70
+
67
71
3. `request.user_id()`: Returns the token subject, same as `request.jwt() ->> 'sub'` and also the same as `token_parameters.user_id` in the previous syntax.
68
72
69
73
The major difference from the previous `token_parameters` is that all payloads are preserved as-is, which can make usage a little more intuitive. This also includes JWT payload fields that were not previously accessible.
70
74
71
75
Migrating to the new syntax:
72
76
73
77
1. `token_parameters.user_id` references can simply be updated to `request.user_id()`
78
+
74
79
2. Custom parameters can be updated from `token_parameters.my_custom_field` to `request.jwt() ->> 'parameters.my_custom_field'`
80
+
75
81
1. This example applies if you keep your existing custom JWT as is.
82
+
76
83
2. Supabase users can now make use of [Supabase's standard JWT structure](https://supabase.com/docs/guides/auth/jwts#jwts-in-supabase) and reference `app_metadata.my_custom_field` directly.
77
84
78
85
Example:
@@ -210,6 +217,9 @@ The supported SQL is based on a small subset of the SQL standard syntax.
210
217
Notable features and restrictions:
211
218
212
219
1. Only simple `SELECT` statements are supported.
220
+
213
221
2. No `JOIN`, `GROUP BY` or other aggregation, `ORDER BY`, `LIMIT`, or subqueries are supported.
222
+
214
223
3. For token parameters, only `=` operators are supported, and `IN` to a limited extent.
224
+
215
225
4. A limited set of operators and functions are supported — see [Operators and Functions](/usage/sync-rules/operators-and-functions).
0 commit comments