auto_subscribe: true so streams sync automatically when clients connect.
Beta ReleaseSync Streams are now in beta and production-ready. We recommend Sync Streams for all new projects, and encourage existing projects to migrate from Sync Rules.We welcome your feedback — please share with us in Discord.
Defining Streams
Streams are defined in a configuration file. Each stream has a name and a query that specifies which rows to sync using SQL-like syntax. The query can reference parameters like the authenticated user’s ID to personalize what each user receives.- PowerSync Cloud
- Self-Hosted
In the PowerSync Dashboard:
- Select your project and instance
- Go to Sync Streams
- Edit the YAML directly in the dashboard
- Click Deploy to validate and deploy
| Option | Default | Description |
|---|---|---|
query | — | SQL-like query defining which data to sync. Use either query or queries, not both. See Writing Queries. |
queries | — | Array of queries defining which data to sync. More efficient than defining separate streams: the client manages one subscription and PowerSync merges the data from all queries (see Multiple Queries per Stream). |
with | — | CTEs available to this stream’s queries. Define the with block inside each stream. |
auto_subscribe | false | When true, clients automatically subscribe on connect. |
priority | — | Sync priority (lower value = higher priority). See Prioritized Sync. |
accept_potentially_dangerous_queries | false | Silences security warnings when queries use client-controlled parameters (i.e. connection parameters and subscription parameters), as opposed to authentication parameters that are signed as part of the JWT. Set to true only if you’ve verified the query is safe. See Using Parameters. |
Basic Examples
There are two independent concepts to understand:- What data the stream returns. For example:
- Global data: No parameters. Same data for all users (e.g. reference tables like categories).
- Filtered data: Filters the data by a parameter value. This can make use of auth parameters from the JWT token (such as the user ID or other JWT claims), subscription parameters (specified by the client when it subscribes to a stream at any time), or connection parameters (specified at connection). Different users will get different sets of data based on the parameters. See Using Parameters for the full reference.
- When the client syncs the data
- Auto-subscribe: Client automatically subscribes on connect (
auto_subscribe: true) - On-demand: Client explicitly subscribes when needed (default behavior)
- Auto-subscribe: Client automatically subscribes on connect (
Global Data
Data without parameters is “global” data, meaning the same data goes to all users/clients. This is useful for reference tables:Global data streams still require clients to subscribe explicitly unless you set
auto_subscribe: trueFiltering Data by User
Useauth.user_id() or other JWT claims to return different data per user:
Filtering Data Based on Subscription Parameters
Usesubscription.parameter() for data that clients subscribe to explicitly:
Using Auto-Subscribe
Setauto_subscribe: true to sync data automatically when clients connect. This is useful for:
- Reference data that all users need, or that are needed in many screens in the app.
- User data that should always be available offline
- Maintaining Sync Rules default behavior (“sync everything upfront”) when migrating to Sync Streams
Client-Side Usage
Subscribe to streams from your client app:- JavaScript/TypeScript
- Dart
- Kotlin
- Swift
- .NET
useQuery hook can wait for Sync Streams before running queries:TTL (Time-To-Live)
Each subscription has attl that keeps data cached after unsubscribing. This enables warm cache behavior — when users return to a screen and you re-subscribe to relevant streams, data is already available on the client. Default TTL is 24 hours. See Client-Side Usage for details.
Developer Notes
-
SQL Syntax: Stream queries use a SQL-like syntax with
SELECTstatements. You can use subqueries,INNER JOIN, and CTEs for filtering.GROUP BY,ORDER BY, andLIMITare not supported. See Writing Queries for details on joins, multiple queries per stream, and other features. -
Type Conversion: Data types from your source database (Postgres, MongoDB, MySQL, SQL Server) are converted when synced to the client’s SQLite database. SQLite has a limited type system, so most types become
textand you may need to parse or cast values in your app code. See Type Mapping for details on how each type is handled. -
Primary Key: PowerSync requires every synced table to have a primary key column named
idof typetext. If your backend uses a different column name or type, you’ll need to map it. For MongoDB, collections use_idas the ID field; you must alias it in your stream queries (e.g.SELECT _id as id, * FROM your_collection). - Case Sensitivity: To avoid issues across different databases and platforms, use lowercase identifiers for all table and column names in your Sync Streams. If your backend uses mixed case, see Case Sensitivity for how to handle it.
- Bucket Limits: PowerSync uses internal partitions called buckets to efficiently sync data. There’s a default limit of 1,000 buckets per user/client. Each unique combination of a stream and its parameters creates one bucket, so keep this in mind when designing streams that use subscription parameters. You can use multiple queries per stream to reduce bucket count.
- Troubleshooting: If data isn’t syncing as expected, the Sync Diagnostics Client helps you inspect what’s happening for a specific user — you can see which buckets the user has and what data is being synced.