SQLDelight support is currently in beta.
Maven: com.powersync:integration-sqldelight
Features
When adopting SQLDelight with PowerSync, you can safely define your SQL statements and let the SQLDelight compiler generate code to map rows into typed classes. AllFlow
s from SQLDelight will automatically update for PowerSync writes (including those from
sync).
Installation
This guide assumes that you already have a PowerSync database for Kotlin. See the general documentation for notes on getting started with PowerSync. To use SQLDelight, you can generally follow SQLDelight documentation. A few steps are different though, and these are highlighted here. In addition to SQLDelight, add a dependency oncom.powersync:integration-sqldelight
.
When defining your schema, note that the CREATE TABLE
statements don’t actually run. PowerSync creates views
for the schema passed to the PowerSyncDatabase
factory instead. This also means that triggers, views and indexes
defined in .sq
files are ignored.
To ensure your defined queries are valid, the CREATE TABLE
syntax should still mirror your PowerSync schema.
Since PowerSync links SQLite, configure SQLDelight to not do that in your build.gradle.kts
file:
Usage
Assuming that your SQLDelight database and its queries have been defined and that you’ve opened thePowerSyncDatabase
,
you can create your SQLDelight database ontop of PowerSync:
PowerSyncDriver
will automatically keep the two databases in sync and update SQLDelight flows
for all writes, regardless of whether they’ve been issued against the sqldelight
database or against the source
powersync
connection.