suspendTransaction
Creates a suspendable transaction with the specified transactionIsolation and readOnly settings, then calls the statement block with this transaction as its receiver and returns the result.
Note If the database value db is not set, the value used will be either the last Database instance created or the value associated with the parent transaction (if this function is invoked in an existing transaction).
Note This function catches all throwables (including errors) to ensure proper transaction rollback and resource cleanup, even in exceptional circumstances.
Note The JDBC driver calls inside statement are still blocking, and they run on the caller's dispatcher. If a transaction waits for a row lock (for example, with forUpdate()) that is held by a suspended transaction on the same single-threaded dispatcher (such as a plain runBlocking {}), the lock owner can never resume to release it and both transactions deadlock. Run such transactions on a dispatcher with enough threads, for example withContext(Dispatchers.IO) { suspendTransaction { ... } }.
Return
The final result of the statement block.
Parameters
Database to use for the transaction. Defaults to null.
Transaction isolation level. Defaults to db.transactionManager.defaultIsolationLevel.
Whether the transaction should be read-only. Defaults to db.transactionManager.defaultReadOnly.
Throws
If no database is available
If a database error occurs and retry attempts are exhausted
If any other error occurs during execution