getCrudTransactions

abstract suspend fun getCrudTransactions(): Flow<CrudTransaction>(source)

Obtains a flow emitting completed transactions with local writes against the database.

This is typically used from the PowerSyncBackendConnector.uploadData callback. Each entry emitted by the returned flow is a full transaction containing all local writes made while that transaction was active.

Unlike getNextCrudTransaction, which always returns the oldest transaction that hasn't been CrudTransaction.completed yet, this flow can be used to collect multiple transactions. Calling CrudTransaction.complete will mark that and all prior transactions emitted by the flow as completed.

This can be used to upload multiple transactions in a single batch, e.g with:

val batch = mutableListOf<CrudEntry>()
var lastTx: CrudTransaction? = null

database.getCrudTransactions().takeWhile { batch.size < 100 }.collect {
batch.addAll(it.crud)
lastTx = it
}

if (batch.isNotEmpty()) {
uploadChanges(batch)
lastTx!!.complete(null)
}

If there is no local data to upload, returns an empty flow.