RoomConnectionPool

A SQLiteConnectionPool implementation for the PowerSync SDK that is backed by a RoomDatabase.

An instance of this class can be passed to com.powersync.PowerSyncDatabase.opened, allowing PowerSync to wrap Room databases.

Writes made from the wrapped PowerSync database, including writes made for the sync process, are forwarded to Room and will update your flows automatically.

On the other hand, the PowerSync SDK needs to be notified about updates in Room. For that, a schema parameter can be used in the constructor. It will call syncRoomUpdatesToPowerSync to collect a Room flow on all tables. Alternatively, transferPendingRoomUpdatesToPowerSync can be called after issuing writes in Room to transfer them to PowerSync.

Constructors

Link copied to clipboard
constructor(db: RoomDatabase, schema: Schema? = null)

Properties

Link copied to clipboard
open override val updates: SharedFlow<Set<String>>

Functions

Link copied to clipboard
open suspend override fun close()
Link copied to clipboard
open suspend override fun <T> read(callback: suspend (SQLiteConnectionLease) -> T): T
Link copied to clipboard

Registers a Room listener on all tables mentioned in the schema and invokes transferPendingRoomUpdatesToPowerSync when they change.

Link copied to clipboard

Makes pending updates tracked by Room's invalidation tracker available to the PowerSync database, updating flows and triggering CRUD uploads.

Link copied to clipboard
open suspend override fun <R> withAllConnections(action: suspend (SQLiteConnectionLease, List<SQLiteConnectionLease>) -> R)
Link copied to clipboard
open suspend override fun <T> write(callback: suspend (SQLiteConnectionLease) -> T): T