PowerSync SDK on NuGet
This SDK is distributed via NuGet
Source Code
Refer to the
powersync-dotnet repo on GitHubAPI Reference (Coming soon)
A full API Reference for this SDK is not yet available. This is planned for a future release.
Example Projects
Gallery of example projects/demo apps built with .NET PowerSync
Changelog
Changelog for the SDK
Supported Frameworks and Targets
The PowerSync .NET SDK supports:- .NET Versions: 6, 8, and 9
- .NET Framework: Version 4.8 (requires additional configuration)
- MAUI: Cross-platform support for Android, iOS, and Windows
- WPF: Windows desktop applications
- Blazor (web) platforms are not yet supported.
SDK Features
- Provides real-time streaming of database changes.
- Offers direct access to the SQLite database, enabling the use of SQL on both client and server sides.
- Provides watched queries that allow listening for live updates to data.
- Eliminates the need for client-side database migrations as these are managed automatically.
Quickstart
- Common
- MAUI
For desktop/server/binary use-cases and WPF, add the
PowerSync.Common NuGet package to your project:Add
--prerelease while this package is in alpha. To install a specific version, use --version instead: dotnet add package PowerSync.Common --version 0.0.6-alpha.11. Define the Client-Side Schema
This refers to the for the managed SQLite database exposed by the PowerSync Client SDKs, that your app can read from and write to. The schema is applied when the database is instantiated (as we’ll show in the next step) — . You can use this example as a reference when defining your schema. The types available aretext, integer and real. These should map directly to the values produced by the Sync Rules. If a value doesn’t match, it is cast automatically. For details on how backend source database types are mapped to the SQLite types, see Types.
2. Instantiate the PowerSync Database
Next, you need to instantiate the PowerSync database. PowerSync streams changes from your backend source database into the client-side SQLite database, based on your Sync Rules. In your client-side app, you can read from and write to the local SQLite database, whether the user is online or offline. Example: The initialization syntax differs slightly between the Common and MAUI SDKs:- Common
- MAUI
3. Integrate with your Backend
The PowerSync backend connector provides the connection between your application backend and the PowerSync client-side managed SQLite database. It is used to:- Retrieve an auth token to connect to the PowerSync instance.
- Upload client-side writes to your backend API. Any writes that are made to the SQLite database are placed into an upload queue by the PowerSync Client SDK and automatically uploaded to your app backend (where you apply those changes to the backend source database) when the user is connected.
- PowerSyncBackendConnector.FetchCredentials - This method will be automatically invoked by the PowerSync Client SDK every couple of minutes to obtain authentication credentials. See Authentication Setup for instructions on how the credentials should be generated.
- PowerSyncBackendConnector.UploadData - This method will be automatically invoked by the PowerSync Client SDK whenever it needs to upload client-side writes to your app backend via your backend API. Therefore, in your implememtation, you need to define how your backend API is called. See Writing Client Changes for considerations on the app backend implementation.
connect to start syncing data with your backend:
Using PowerSync: CRUD functions
Once the PowerSync instance is configured you can start using the SQLite DB functions. The most commonly used CRUD functions to interact with your SQLite data are:PowerSyncDatabase.Get- get (SELECT) a single row from a table.PowerSyncDatabase.GetAll- get (SELECT) a set of rows from a table.PowerSyncDatabase.Watch- execute a read query every time source tables are modified.PowerSyncDatabase.Execute- execute a write (INSERT/UPDATE/DELETE) query.
Fetching a Single Item
TheGet method executes a read-only (SELECT) query and returns a single result. It throws an exception if no result is found. Use GetOptional to return a single optional result (returns null if no result is found).
Querying Items (PowerSync.GetAll)
TheGetAll method returns a set of rows from a table.
Watching Queries (PowerSync.Watch)
TheWatch method executes a read query whenever a change to a dependent table is made.
Mutations (PowerSync.Execute)
TheExecute method can be used for executing single SQLite write statements.
Configure Logging
Enable logging to help you debug your app. By default, the SDK uses a no-op logger that doesn’t output any logs. To enable logging, you can configure a custom logger using .NET’sILogger interface:
Additional Usage Examples
For more usage examples including accessing connection status, monitoring sync progress, and waiting for initial sync, see the Usage Examples page.Troubleshooting
See Troubleshooting for pointers to debug common issues.Supported Platforms
See Supported Platforms -> .NET SDK.Upgrading the SDK
To upgrade to the latest version of the PowerSync package, run the below command in your project folder:- Common
- MAUI
Add
--prerelease while this package is in alpha. To install a specific version, use --version instead: dotnet add package PowerSync.Common --version 0.0.6-alpha.1