withTransaction

context(ec: ExecContext)
inline suspend fun <R> DatabaseService.withTransaction(crossinline block: context(Transaction) suspend () -> R): R(source)

Executes a transactional context for a given operation. The operation is wrapped in a database transaction and executed while tracking its duration using OpenTelemetry.

Return

The result of the function execution within the transactional context.

Parameters

block

The function to be executed within a database transaction. This function is provided with an implicit Transaction context and can return a result of type R.