Room support is currently in alpha!While we don’t expect any major changes and the library is tested on multiple platforms, it depends on raw tables,
an unstable PowerSync feature.
Maven: com.powersync:integration-room
Features
When adopting the Room integration for PowerSync:- PowerSync will use the connection pool of the Room database for efficient queries.
- Local writes from Room will update watched PowerSync queries, and they will trigger a CRUD upload.
- Writes from PowerSync (including those made by the sync client) will immediately update your Room flows!
Installation
PowerSync acts as an addon to your existing Room database, which means that (unlike with most other PowerSync SDKs) you are still responsible for schema management. Room requires raw tables, as the views managed by PowerSync are incompatible with the schema verification when Room opens the database. To add PowerSync to your Room database,- Add a dependency on
com.powersync:core
andcom.powersync:integration-room
. - Add a dependency on
androidx.sqlite:sqlite-bundled
: Since PowerSync uses a SQLite extension (which are unsupported on the platform SQLite libraries on both Android and iOS), you need to bundle a SQLite with your app. On theRoomDatabase.Builder
, callsetDriver()
with a PowerSync-enabled driver:
Setup
Because PowerSync syncs into tables that you’ve created with Room, it needs to know which SQL statements to run for inserts, updates and deletes. Let’s say you had a table like the following:RawTable
in the schema:
- The SQL statements must match the schema created by Room.
- The
RawTable.name
andPendingStatementParameter.Column
values must match the table and column names of the synced table from the PowerSync service, derived from your sync rules.
PowerSyncDatabase
instance which is backed by Room:
PowerSyncDatabase
behaves just like a regular PowerSync database, meaning that you can call
connect
to establish a sync connection: