DATE:
AUTHOR:
PowerSync Product Team
Dart/Flutter SDK React Native SDK Kotlin SDK JavaScript/Web SDK Swift SDK Node.js SDK .NET SDK Capacitor SDK Rust SDK Tauri SDK

Connect for Downloads or Uploads Only

DATE:
AUTHOR: PowerSync Product Team

PowerSync syncs data in two directions. The client SDK downloads changes from the PowerSync Service into your app's local SQLite database, using a token for the current user. The SDK also calls your upload code, which sends your app's local changes (mutations) to your backend. Your backend then applies them to your source database.

Until now, you supplied the token and the upload code together, in one backend connector (PowerSyncBackendConnector in the JavaScript SDK). The client SDKs now let you pass them to connect() as separate parts:

  • The authenticator resolves the token the SDK uses to download changes from the PowerSync Service into your local SQLite database.

  • The mutation uploader sends your app's local mutations from the same local SQLite database to your backend's write endpoint, which applies them to your source database.

You can pass both, or only the one your app needs. A download-only app needs no upload code, and an upload-only app doesn't connect to the PowerSync Service at all.

Example use cases

  • Offline catalogs: Store devices sync a product catalog and prices, so staff can browse them offline. Staff don't change the data, so the app connects with only an authenticator.

  • Analytics and logs: The app queues analytics events and logs on the device and uploads them to your backend. It connects with only a mutation uploader, so it needs no PowerSync Service instance.

  • Device data capture: Devices upload scans or sensor readings and don't need any server data. They also connect with only a mutation uploader.

How it works

You pass the parts you need to connect(), plus the URL of you PowerSync Service instance for downloads, and the authenticator returns only the token. This example uses JavaScript:

// Downloads and uploads
await db.connect({ powerSyncEndpoint: instanceUrl, authenticator: new MyAuthenticator(), upload: uploadData });

// Downloads only
await db.connect({ powerSyncEndpoint: instanceUrl, authenticator: new MyAuthenticator() });

// Uploads only: the SDK doesn't connect to the PowerSync Service
await db.connect({ upload: uploadData });

To connect this way in your SDK, see Connect for Downloads or Uploads Only.

Switching from a backend connector

If your app already uses a backend connector, what you need to do depends on your SDK and whether you use checkpoint requests:

  • Rust and Tauri: You need to switch. Rust SDK 0.2.0 and tauri-plugin-powersync 0.3.0 removed backend connectors. To connect with an authenticator and a mutation uploader, follow the Rust or Tauri SDK reference.

  • Other SDKs: Your backend connector keeps working, so you don't need to switch yet. We plan to deprecate backend connectors in a future release, so we recommend switching. To switch, follow the migration steps.

  • Checkpoint requests (alpha): The checkpoint request type now builds on the authenticator. In Kotlin, Swift and .NET, a connector class that only extends or implements it must also implement the backend connector type. When you switch, follow Authenticator Changes to move postCheckpointRequest() to your authenticator.

Requirements

  • JavaScript: @powersync/web 2.6.0, @powersync/react-native 2.4.0, @powersync/node 1.3.0 or @powersync/capacitor 0.10.0

  • Dart/Flutter: powersync 2.6.0

  • Kotlin: 1.16.0, or 1.16.1 for the Supabase integration's SupabaseAuthenticator and SupabaseUploader

  • Swift: 1.17.0

  • .NET: PowerSync.Common 1.0.1

  • Rust: 0.2.0

  • Tauri: tauri-plugin-powersync 0.3.0

Learn more

To learn how the authenticator and the mutation uploader work, read Client-Side Integration. For starter code to copy into your app, including for Supabase, see Client Connection Examples. For the thinking behind the design, read the proposal discussion.

Questions or feedback? Reach us on Discord or X.

Powered by LaunchNotes