- Authentication Parameters, which come from the JWT token.
- Client Parameters, which are passed directly from clients (specified at connection)
- Values From a Table/Collection (in your source database)
Parameter Queries are not run directly on your source database. Instead, the Parameter Queries in your Sync Rules are used to pre-process rows/documents as they are replicated from your source database. During replication, parameter values are indexed for efficient use in the sync process.
Using Authentication Parameters
The following functions allow you to select Authentication Parameters in your Parameter Queries:| Function | Description |
|---|---|
request.user_id() | Returns the JWT subject (sub). Same as request.jwt() ->> 'sub' (see below) |
request.jwt() | Returns the entire (signed) JWT payload as a JSON string. If there are other claims in your JWT (in addition to the user ID), you can select them from this JSON string. |
request.jwt() is a string containing JSON, use the ->> operator to select values from it:
Legacy Syntax (`token_parameters`)
Legacy Syntax (`token_parameters`)
A legacy syntax for Parameter Queries used That legacy syntax also allowed custom claims from the JWT, but only if they were nested under a
token_parameters.user_id to return the JWT subject. Example:parameters claim in the JWT.If you are still using this legacy syntax, you can migrate to the current syntax as follows:-
token_parameters.user_idreferences can simply be updated torequest.user_id() -
For custom parameters, if you keep your custom JWT in the format required by the legacy syntax, you can update
token_parameters.my_custom_fieldreferences torequest.jwt() ->> 'parameters.my_custom_field' -
Alternatively, you can get custom parameters directly from the JWT payload/claims, e.g.
request.jwt() ->> 'my_custom_field'
Using Client Parameters
| Function | Description |
|---|---|
request.parameters() | Returns Client Parameters as a JSON string. |
Using Values From a Table/Collection
A Parameter Query can select a parameter from a table/collection in your source database, for example:Supported SQL
The supported SQL in Parameter Queries is based on a small subset of the SQL standard syntax. Not all SQL constructs are supported. See Supported SQL for full details.Usage Examples
Filter on Additional Columns/Fields
Group According to Different Columns/Fields
Using Different Tables/Collections for Parameters
Multiple Columns/Fields
Parameter Queries may select multiple columns/fields parameters.Using a Join Table/Collection
In this example, the Parameter Query can return multiple rows/documents, resulting in multiple sets of bucket parameters for a single user.Expanding JSON Array Into Multiple Parameters
Using thejson_each() function and -> operator, we can expand a parameter that is a JSON array into multiple rows, thereby filtering by multiple parameter values: