DatabaseClient

class DatabaseClient<out VertxSqlClientT : SqlClient>(val vertxSqlClient: VertxSqlClientT, val config: DatabaseClientConfig) : CoroutineAutoCloseable, StatementPreparationExposedTransactionProvider(source)

The main entry point for executing database operations using Vert.x SQL Client with Exposed SQL generation.

This client wraps a Vert.x SqlClient for reactive query execution and uses Exposed for SQL generation, combining the type-safe SQL DSL of Exposed with the reactive, non-blocking capabilities of Vert.x.

Parameters

VertxSqlClientT

the type of Vert.x SQL client, which can be SqlClient, Pool, or SqlConnection or one of its database-specific subtypes.

vertxSqlClient

the Vert.x SQL client used for executing queries.

config

the configuration for this client, including SQL transformation, transaction settings, and the transaction provider for SQL statement preparation.

See also

Constructors

Link copied to clipboard
constructor(vertxSqlClient: VertxSqlClientT, config: DatabaseClientConfig)
constructor(vertxSqlClient: VertxSqlClientT, exposedDatabase: Database, config: DatabaseClientConfig)

Secondary constructor that accepts a Database for backward compatibility.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
val exposedDatabase: Database

The Exposed Database used for SQL generation.

Link copied to clipboard

Functions

Link copied to clipboard
open suspend override fun close()
Link copied to clipboard
suspend fun createTable(table: Table): Int
Link copied to clipboard
suspend fun <SqlResultT : SqlResult<*>> doExecute(statement: Statement<*>, transformQuery: PreparedQuery<RowSet<Row>>.() -> PreparedQuery<SqlResultT>): SqlResultT
Link copied to clipboard
suspend fun dropTable(table: Table): Int
Link copied to clipboard
suspend fun <SqlResultT : SqlResult<*>> execute(statement: Statement<*>, transformQuery: PreparedQuery<RowSet<Row>>.() -> PreparedQuery<SqlResultT>): SqlResultT
Link copied to clipboard
suspend fun <SqlResultT : SqlResult<*>> executeBatch(statements: Iterable<Statement<*>>, transformQuery: PreparedQuery<RowSet<Row>>.() -> PreparedQuery<SqlResultT>): Sequence<SqlResultT>
suspend fun executeBatchForVertxSqlClientRowSetSequence(statements: Iterable<Statement<*>>): Sequence<RowSet<Row>>
Link copied to clipboard
suspend fun executeBatchQuery(queries: Iterable<Query>, getFieldExpressionSetWithExposedTransaction: Boolean = config.autoExposedTransaction): Sequence<RowSet<ResultRow>>

See the KDoc of the overload with resultRowMapper parameter.

suspend fun executeBatchQuery(fieldSet: FieldSet, queries: Iterable<Query>): Sequence<RowSet<ResultRow>>
inline suspend fun <Data> executeBatchQuery(queries: Iterable<Query>, getFieldExpressionSetWithExposedTransaction: Boolean = config.autoExposedTransaction, crossinline resultRowMapper: ResultRow.() -> Data): Sequence<RowSet<Data>>
inline suspend fun <Data> executeBatchQuery(fieldSet: FieldSet, queries: Iterable<Query>, getFieldExpressionSetWithExposedTransaction: Boolean = config.autoExposedTransaction, crossinline resultRowMapper: ResultRow.() -> Data): Sequence<RowSet<Data>>
Link copied to clipboard
suspend fun executeBatchUpdate(statements: Iterable<Statement<Int>>): Sequence<Int>

Executes a batch of update statements, including InsertStatement and UpdateStatement.

Link copied to clipboard
inline suspend fun <T> executeExpression(expression: Expression<T>): T
suspend fun <T : Any> executeExpression(clazz: KClass<T>, expression: Expression<T?>): T?
Link copied to clipboard
suspend fun executeForVertxSqlClientRowSet(statement: Statement<*>): RowSet<Row>
Link copied to clipboard
suspend fun executePlainSql(sql: String): RowSet<Row>

Use SqlClient.preparedQuery here because of SqlConnectOptions.setCachePreparedStatements.

Link copied to clipboard
suspend fun executePlainSqlUpdate(sql: String): Int
Link copied to clipboard
suspend fun executeQuery(query: Query, getFieldExpressionSetWithExposedTransaction: Boolean = config.autoExposedTransaction): RowSet<ResultRow>
inline suspend fun <Data> executeQuery(query: Query, getFieldExpressionSetWithExposedTransaction: Boolean = config.autoExposedTransaction, crossinline resultRowMapper: ResultRow.() -> Data): RowSet<Data>
Link copied to clipboard
suspend fun executeQueryForList(query: Query, getFieldExpressionSetWithExposedTransaction: Boolean = config.autoExposedTransaction): List<ResultRow>

An alternative API to executeQuery that returns a List instead of a RowSet.

Link copied to clipboard
suspend fun executeSingleOrNoUpdate(statement: Statement<Int>): Boolean
Link copied to clipboard
suspend fun executeSingleUpdate(statement: Statement<Int>)
Link copied to clipboard
suspend fun executeUpdate(statement: Statement<Int>): Int
Link copied to clipboard
suspend fun <U> executeWithMapping(statement: Statement<*>, rowMapper: Function<Row, U>): RowSet<U>
Link copied to clipboard
fun <T> exposedReadOnlyTransaction(statement: Transaction.() -> T): T
Link copied to clipboard
fun <T> exposedTransaction(transactionIsolation: Int? = exposedDatabase/*?*/.transactionManager/*?*/.defaultIsolationLevel, readOnly: Boolean? = exposedDatabase/*?*/.transactionManager/*?*/.defaultReadOnly, statement: Transaction.() -> T): T
Link copied to clipboard
suspend fun DatabaseClient<Pool>.getConnectionClient(): DatabaseClient<SqlConnection>
fun Query.getFieldExpressionSetWithOptionalReadOnlyExposedTransaction(getFieldExpressionSetWithExposedTransaction: Boolean): Set<Expression<*>>
Link copied to clipboard
fun FieldSet.getFieldExpressionSetWithTransaction(): Set<Expression<*>>
fun Query.getFieldExpressionSetWithTransaction(): Set<Expression<*>>
Link copied to clipboard
suspend fun DatabaseClient<Pool>.getVertxPoolConnection(): SqlConnection
Link copied to clipboard
suspend fun isWorking(): Boolean
inline fun <T> optionalStatementPreparationExposedTransaction(withExposedTransaction: Boolean, crossinline block: () -> T): T
Link copied to clipboard
fun prepareBatchSqlAndArgTuples(statements: Iterable<Statement<*>>): Pair<String?, List<Tuple>>
fun Transaction.prepareBatchSqlAndArgTuplesWithProvidedTransaction(statements: Iterable<Statement<*>>): Pair<String?, List<Tuple>>
Link copied to clipboard
fun prepareSqlAndArgTuple(statement: Statement<*>): Pair<String, Tuple?>
Link copied to clipboard
open override fun <T> statementPreparationExposedTransaction(block: Transaction.() -> T): T

Executes the given block within an Exposed transaction context suitable for SQL statement preparation.

Link copied to clipboard
suspend fun <T> DatabaseClient<Pool>.withConnectionClient(block: suspend (DatabaseClient<SqlConnection>) -> T): T
open override fun <T> withExplicitOnlyStatementPreparationExposedTransaction(block: Transaction.() -> T): T

Executes the given block within an Exposed transaction context suitable for SQL statement preparation, without storing the transaction in ThreadLocal or coroutine context.

Link copied to clipboard
suspend fun <SqlConnectionT : SqlConnection, T> DatabaseClient<SqlConnectionT>.withSavepoint(savepointName: String, function: suspend (DatabaseClient<SqlConnectionT>) -> T): T
Link copied to clipboard
suspend fun <SqlConnectionT : SqlConnection, T> DatabaseClient<SqlConnectionT>.withSavepointAndRollbackIfThrows(savepointName: String, function: suspend (DatabaseClient<SqlConnectionT>) -> T): T

An alias of withSavepoint.

Link copied to clipboard
suspend fun <SqlConnectionT : SqlConnection, T> DatabaseClient<SqlConnectionT>.withSavepointAndRollbackIfThrowsOrNone(savepointName: String, function: suspend (DatabaseClient<SqlConnectionT>) -> Option<T>): Option<T>
Link copied to clipboard

Currently only supported with PostgreSQL. A savepoint destroys one with the same name so be careful.

Link copied to clipboard
@JvmName(name = "withTransactionForSqlConnection")
suspend fun <SqlConnectionT : SqlConnection, T> DatabaseClient<SqlConnectionT>.withTransaction(function: suspend (DatabaseClient<SqlConnectionT>) -> T): T

@JvmName(name = "withTransactionForPool")
suspend fun <T> DatabaseClient<Pool>.withTransaction(function: suspend (DatabaseClient<SqlConnection>) -> T): T

When using this function, it's recommended to name the lambda parameter the same as the outer receiver so that the outer DatabaseClient is shadowed, and so that you don't call the outer DatabaseClient without a transaction by accident.

Link copied to clipboard
suspend fun <SqlConnectionT : SqlConnection, T> DatabaseClient<SqlConnectionT>.withTransactionCommitOrRollback(function: suspend (DatabaseClient<SqlConnectionT>) -> Option<T>): Option<T>
Link copied to clipboard
@JvmName(name = "withTransactionEitherForSqlConnection")
suspend fun <SqlConnectionT : SqlConnection, RollbackResult, CommitResult> DatabaseClient<SqlConnectionT>.withTransactionEither(function: suspend (DatabaseClient<SqlConnectionT>) -> Either<RollbackResult, CommitResult>): Either<RollbackResult, CommitResult>

@JvmName(name = "withTransactionEitherForPool")
suspend fun <RollbackResult, CommitResult> DatabaseClient<Pool>.withTransactionEither(function: suspend (DatabaseClient<SqlConnection>) -> Either<RollbackResult, CommitResult>): Either<RollbackResult, CommitResult>

When using this function, it's recommended to name the lambda parameter the same as the outer receiver so that the outer DatabaseClient is shadowed, and so that you don't call the outer DatabaseClient without a transaction by accident.

Link copied to clipboard

Polymorphic transaction function for DatabaseClient<*> with either Pool or SqlConnection as the DatabaseClient.vertxSqlClient.

Link copied to clipboard
suspend fun <T> DatabaseClient<*>.withTransactionPolymorphic(function: suspend (DatabaseClient<SqlConnection>) -> T): T

Polymorphic transaction function for DatabaseClient<*> with either Pool or SqlConnection as the DatabaseClient.vertxSqlClient.

Link copied to clipboard
inline suspend fun <SqlConnectionT : SqlConnection, T> DatabaseClient<Pool>.withTypedTransaction(crossinline function: suspend (DatabaseClient<SqlConnectionT>) -> T): T

A variant of withTransaction that casts the SqlConnection to a specific subtype.

Link copied to clipboard
inline suspend fun <SqlConnectionT : SqlConnection, T> DatabaseClient<*>.withTypedTransactionPolymorphic(noinline function: suspend (DatabaseClient<SqlConnectionT>) -> T): T

Polymorphic transaction function for DatabaseClient<*> with either Pool or SqlConnection as the DatabaseClient.vertxSqlClient.

Link copied to clipboard