transactional

inline suspend fun <R> Database.transactional(readOnly: Boolean = false, crossinline block: suspend Transaction.() -> R): R(source)

Acquires a database connection, runs the block, commits the changes and closes the connection.

If all connections are used, this function suspends until a connection is available.

If BDatabaseConfig.dumpLongTransactions is enabled, a coroutine dump (if available) and a thread dump will be done if the transaction is longer than the threshold.

Supports nesting, but it is not recommended doing so, avoid nesting by returning the data as soon as possible.

Parameters

readOnly

true if the database only is read from, can allow some optimizations but does not prevent writing

See also