← Back to Stormify Documentation

transaction

suspend fun <R> transaction(block: suspend () -> R): R

Execute block inside a transaction. Commits on success, rolls back on any throwable.

Whatever block throws propagates unchanged after the rollback, as from the blocking Stormify.transaction; the transaction's own failures (begin, commit) are onl.ycode.kdbc.SQLExceptions. A cancelled coroutine ends in a CancellationException, with the failure of the interrupted statement as its cause.

If called from inside another transaction { } on the same SuspendStormify, opens a savepoint on the ambient connection. If called from inside a bare withConnection { }, runs a full BEGIN/COMMIT cycle on that connection. While the block runs, convenience operations on the underlying Stormify transparently route through this transaction's connection.