connect() on it, which causes the PowerSync Client SDK to connect to the PowerSync Service for the purpose of syncing data to the client-side SQLite database, and to connect to your backend application as needed, for two potential purposes:
| Purpose | Description |
|---|---|
| Uploading mutations to your backend: | Mutations that are made to the client-side SQLite database are uploaded to your backend application, where you control how they’re applied to your backend source database (Postgres, MongoDB, MySQL, or SQL Server). This is how PowerSync achieves bi-directional syncing of data: The PowerSync Service provides the server-to-client read path based on your Sync Rules or Streams, and the client-to-server write path goes via your backend. |
| Authentication integration: (optional) | PowerSync uses JWTs for authentication between the Client SDK and PowerSync Service. Some authentication providers already generate JWTs for users which PowerSync can verify directly. For others, some backend code must be added to your application backend to generate the JWTs. |
connect() on the client-side PowerSync database. You must define that backend connector, and it must implement two functions/methods:
| Purpose | Function | Description |
|---|---|---|
| Uploading mutations to your backend: | uploadData() | The PowerSync Client SDK automatically calls this function to upload client-side mutations to your backend. Whenever you write to the client-side SQLite database, those writes are also automatically placed into an upload queue by the Client SDK, and the Client SDK processes the entries in the upload queue by calling uploadData(). You should define your uploadData() function to call your backend application API to upload and apply the write operations to your backend source database. The Client SDK automatically handles retries in the case of failures. See Writing Data in the Client SDKs section for more details on the implementation of uploadData(). |
| Authentication integration: | fetchCredentials() | This is called every couple of minutes and is used to obtain a JWT. The PowerSync Client SDK uses that JWT to authenticate against the PowerSync Service. See Authentication Setup for more details. |