Database

class Database(dataSource: DataSource, deadlockDetector: DeadlockDetector = DefaultDeadlockDetector, backoffStrategy: BackoffStrategy = DEFAULT_BACKOFF_STRATEGY, attempts: Int = DEFAULT_ATTEMPTS)

A thin layer on top of the JDBC API that enforces the use of transactions, automatically retrying them on deadlock, and provides coroutine integration.

Connection pooling is not provided by this library. A separate connection pooling library (such as HikariCP or the functionality built into your database driver) should be used in combination with this library.

Constructors

Link copied to clipboard
constructor(dataSource: DataSource, deadlockDetector: DeadlockDetector = DefaultDeadlockDetector, backoffStrategy: BackoffStrategy = DEFAULT_BACKOFF_STRATEGY, attempts: Int = DEFAULT_ATTEMPTS)

Functions

Link copied to clipboard
suspend fun <T> execute(transaction: Transaction<T>): T

Executes a Transaction. If the transaction fails due to deadlock, it is retried up to attempts times in total (including the first attempt).

Link copied to clipboard
fun <T> executeOnce(transaction: Transaction<T>): T

Executes a Transaction. If the transaction fails due to deadlock, it is not retried. This method should therefore only be used if the Transaction.execute method has side effects.