Code snippets and guidelines for common scenarios
OPFSCoopSyncVFS
virtual file system to ensure stable multi-tab functionality.shared-DB-worker-[dbFileName]
and shared-sync-[dbFileName]
will be created.
shared-DB-worker-[dbFileName]
shared-sync-[dbFileName]
fetchCredentials
and uploadData
method of the latest opened available tab. Closing a tab will shift the latest tab to the previously opened one.
Currently, using the SDK in multiple tabs without enabling the enableMultiTabs flag will spawn a standard web worker per tab for DB operations. These workers are safe to operate on the DB concurrently, however changes from one tab may not update watches on other tabs. Only one tab can sync from the PowerSync instance at a time. The sync status will not be shared between tabs, only the oldest tab will connect and display the latest sync status.
Support is enabled by default if available. This can be disabled as below:
tx.rollback()
has not explicitly been called. If an exception is thrown in the callback then changes are automatically rolled back.
downloadProgress
property from the
SyncStatus class. This is especially useful for long-running initial syncs. downloadProgress.downloadedFraction
gives you a value from 0.0 to 1.0 representing the total sync progress.
Example (React, using MUI components):
PowerSyncDatabase
in the JavaScript Web SDK. These flags allow you to enable or disable specific features to suit your application’s requirements.
PowerSyncDatabase
. Flags can be set using the flags
property, which allows you to enable or disable specific functionalities.
true
Enables support for multiple tabs using shared web workers. When enabled, multiple tabs can interact with the same database and sync data seamlessly.false
Enables the broadcasting of logs for debugging purposes. This flag helps monitor shared worker logs in a multi-tab environment.false
Disables warnings when running in SSR (Server-Side Rendering) mode.false
Enables SSR mode. In this mode, only empty query results will be returned, and syncing with the backend is disabled.true
Enables the use of web workers for database operations. Disabling this flag also disables multi-tab support.enableMultiTabs
to true
if your application requires seamless data sharing across multiple tabs.useWebWorker
to true
for efficient database operations using web workers.broadcastLogs
to true
during development to troubleshoot and monitor database and sync operations.disableSSRWarning
to true
when running in SSR mode to avoid unnecessary console warnings.