Skip to content

Commit 9b19b90

Browse files
Documentation edits made through Mintlify web editor
1 parent fbfb9e3 commit 9b19b90

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

usage/sync-rules/parameter-queries.mdx

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Parameter queries allow parameters to be defined on a bucket to group data. Thes
88
bucket_definitions:
99
# Bucket Name
1010
user_buckets:
11-
# Paramter Query
11+
# Parameter Query
1212
parameters: SELECT request.user_id() as user_id
1313
# Data Query
1414
data:
@@ -47,47 +47,45 @@ request.jwt() ->> 'app_metadata.custom_field' -- custom field added by a service
4747
A previous syntax for parameter queries used `token_parameters`. Expand the below for details on how to migrate to the recommended syntax above.
4848
</Note>
4949

50-
<Accordion
51-
title="Previous Syntax"
52-
>
53-
The previous syntax for parameter queries used `token_parameters.user_id` to return the JWT subject. Example:
50+
<Accordion title="Previous Syntax">
51+
The previous syntax for parameter queries used `token_parameters.user_id` to return the JWT subject. Example:
5452

55-
```yaml
56-
bucket_definitions:
57-
by_user_parameter:
58-
parameters: SELECT token_parameters.user_id as user_id
59-
data:
60-
- SELECT * FROM lists WHERE lists.owner_id = bucket.user_id
61-
```
62-
### Migrate to Recommended Syntax
53+
```yaml
54+
bucket_definitions:
55+
by_user_parameter:
56+
parameters: SELECT token_parameters.user_id as user_id
57+
data:
58+
- SELECT * FROM lists WHERE lists.owner_id = bucket.user_id
59+
```
6360
64-
The new functions available in sync rules are:
61+
### Migrate to Recommended Syntax
6562
66-
1. `request.jwt()`: Returns the entire (signed) JWT payload as a JSON string.
67-
2. `request.parameters()`: Returns [client parameters](/usage/sync-rules/advanced-topics/client-parameters) as a JSON string.
68-
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.
63+
The new functions available in sync rules are:
6964
70-
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.
65+
1. `request.jwt()`: Returns the entire (signed) JWT payload as a JSON string.
66+
2. `request.parameters()`: Returns [client parameters](/usage/sync-rules/advanced-topics/client-parameters) as a JSON string.
67+
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.
7168

72-
Migrating to the new syntax:
69+
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.
7370

74-
1. `token_parameters.user_id` references can simply be updated to `request.user_id()`
75-
2. Custom parameters can be updated from `token_parameters.my_custom_field` to `request.jwt() ->> 'parameters.my_custom_field'`
76-
1. This example applies if you keep your existing custom JWT as is.
77-
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.
71+
Migrating to the new syntax:
7872

79-
Example:
73+
1. `token_parameters.user_id` references can simply be updated to `request.user_id()`
74+
2. Custom parameters can be updated from `token_parameters.my_custom_field` to `request.jwt() ->> 'parameters.my_custom_field'`
75+
1. This example applies if you keep your existing custom JWT as is.
76+
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.
8077

81-
```yaml
82-
bucket_definitions:
83-
by_user_parameter:
84-
# request.user_id() is the same as the previous token_parameter.user_id
85-
parameters: SELECT request.user_id() as user_id
86-
data:
87-
- SELECT * FROM lists WHERE lists.owner_id = bucket.user_id
88-
```
89-
</Accordion>
78+
Example:
9079

80+
```yaml
81+
bucket_definitions:
82+
by_user_parameter:
83+
# request.user_id() is the same as the previous token_parameter.user_id
84+
parameters: SELECT request.user_id() as user_id
85+
data:
86+
- SELECT * FROM lists WHERE lists.owner_id = bucket.user_id
87+
```
88+
</Accordion>
9189

9290
#### Filter on additional columns
9391

@@ -132,7 +130,7 @@ bucket_definitions:
132130

133131
In this example, a single query can return multiple sets of bucket parameters for a single user.
134132

135-
Keep in mind that the total number of buckets per user should remain limited (< 1,000), so don't make buckets too granular.
133+
Keep in mind that the total number of buckets per user should remain limited (\< 1,000), so don't make buckets too granular.
136134

137135
```yaml
138136
bucket_definitions:
@@ -181,7 +179,7 @@ bucket_definitions:
181179
- SELECT * FROM todos WHERE todos.list_id = bucket.list_id
182180
```
183181

184-
Keep in mind that the total number of buckets per user should remain limited (< 1,000), so don't make buckets too granular.
182+
Keep in mind that the total number of buckets per user should remain limited (\< 1,000), so don't make buckets too granular.
185183

186184
#### Global buckets
187185

@@ -214,4 +212,4 @@ Notable features and restrictions:
214212
1. Only simple `SELECT` statements are supported.
215213
2. No `JOIN`, `GROUP BY` or other aggregation, `ORDER BY`, `LIMIT`, or subqueries are supported.
216214
3. For token parameters, only `=` operators are supported, and `IN` to a limited extent.
217-
4. A limited set of operators and functions are supported — see [Operators and Functions](/usage/sync-rules/operators-and-functions).
215+
4. A limited set of operators and functions are supported — see [Operators and Functions](/usage/sync-rules/operators-and-functions).

0 commit comments

Comments
 (0)