To sync different sets of data to each user, data is organized into buckets.Each user can sync a number of buckets (up to 1,000), and each bucket defines a set of tables/collections and rows/documents to sync.This is defined using two queries:
Select bucket parameters from a user ID and/or other parameters (parameter queries)
Select data in the bucket using the bucket parameters (data queries)
When designing your buckets, it is recommended, but not required, to group all data in a bucket where the same parameters apply.An example:
Copy
bucket_definitions: user_lists: # Optionally define the priority of the bucket to sync certain buckets before others priority: 1 # See https://docs.powersync.com/usage/use-case-examples/prioritized-sync # Select parameters for the bucket, using the current user_id parameters: SELECT request.user_id() as user_id # (request.user_id() comes from the JWT token) data: # Select data rows/documents using the parameters above - SELECT * FROM lists WHERE owner_id = bucket.user_id
Note:
Table names within Sync Rules must match the names defined in the client-side schema.