withTransaction

suspend fun SqlDriver.withTransaction(context: CoroutineContext = Dispatchers.Default, block: suspend () -> Unit)

Executes block inside a single SQLite transaction.

All INSERT / UPDATE / DELETE operations performed by Kiln repositories inside block have their SqlDriver.notifyListeners calls deferred. After the COMMIT, each dirty table is notified exactly once — reactive flows therefore receive one emission per transaction rather than one per operation.

On any exception the transaction is rolled back and the exception re-thrown. No notifications are sent for a rolled-back transaction.

// Cascade delete with a single Flow emission per affected table:
driver.withTransaction {
taskRepo.deleteByProject(projectId)
projectRepo.delete(projectId)
}

// Batch insert — observers see all rows appear at once:
driver.withTransaction {
tasks.forEach { taskRepo.insert(it) }
}