DatabaseClient

class DatabaseClient<out VertxSqlClient : SqlClient>(val vertxSqlClient: VertxSqlClient, val exposedDatabase: Database, val validateBatch: Boolean = true, val logSql: Boolean = false)(source)

A wrapper client around Vert.x SqlClient for queries and an Exposed Database to generate SQLs working around the limitations of Exposed.

Parameters

validateBatch

whether to validate whether the batch statements have the same generated prepared SQL.

Constructors

Link copied to clipboard
constructor(vertxSqlClient: VertxSqlClient, exposedDatabase: Database, validateBatch: Boolean = true, logSql: Boolean = false)

Properties

Link copied to clipboard
val exposedDatabase: Database
Link copied to clipboard
val logSql: Boolean = false
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
suspend fun <T : Table, E> DatabaseClient<*>.batchInsert(table: T, data: Iterable<E>, body: T.(InsertStatement<Number>, E) -> Unit)
suspend fun <Data : Any> DatabaseClient<*>.batchInsert(table: Table, data: Iterable<Data>, dataUpdateMapper: DataUpdateMapper<Data>)
Link copied to clipboard
suspend fun <T : Table, E> DatabaseClient<*>.batchInsertIgnore(table: T, data: Iterable<E>, body: T.(InsertStatement<Number>, E) -> Unit): Sequence<Boolean>
suspend fun <Data : Any> DatabaseClient<*>.batchInsertIgnore(table: Table, data: Iterable<Data>, dataUpdateMapper: DataUpdateMapper<Data>): Sequence<Boolean>
Link copied to clipboard
suspend fun DatabaseClient<*>.batchInsertSelect(statements: Iterable<InsertSelectStatement>): Sequence<Int>

This function is not conventional and it usages are likely to degrade performance.

Link copied to clipboard
suspend fun <T : Table, E> DatabaseClient<*>.batchSingleOrNoUpdate(table: T, data: Iterable<E>, where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement, E) -> Unit): Sequence<Boolean>
Link copied to clipboard
suspend fun <T : Table, E> DatabaseClient<*>.batchUpdate(table: T, data: Iterable<E>, where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement, E) -> Unit): Sequence<Int>
Link copied to clipboard
suspend fun close()
Link copied to clipboard
suspend fun createTable(table: Table): Int
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.deleteIgnoreWhere(table: T, limit: Int? = null, offset: Long? = null, op: T.(ISqlExpressionBuilder) -> Op<Boolean>): Int
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.deleteWhere(table: T, limit: Int? = null, offset: Long? = null, op: T.(ISqlExpressionBuilder) -> Op<Boolean>): 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(fieldSet: FieldSet, queries: Iterable<Query>): Sequence<RowSet<ResultRow>>
inline suspend fun <Data> executeBatchQuery(fieldSet: FieldSet, queries: Iterable<Query>, 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 <T : Table> DatabaseClient<*>.executeInsertIgnore(table: T, body: T.(InsertStatement<Number>) -> Unit): Boolean
Link copied to clipboard
suspend fun executePlainSql(sql: String): RowSet<Row>

Use SqlClient.preparedQuery here because of PgConnectOptions.setCachePreparedStatements.

Link copied to clipboard
suspend fun executePlainSqlUpdate(sql: String): Int
Link copied to clipboard
suspend fun executeQuery(query: Query): RowSet<ResultRow>
inline suspend fun <Data> executeQuery(query: Query, crossinline resultRowMapper: ResultRow.() -> Data): RowSet<Data>
Link copied to clipboard
suspend fun <Data : Any> DatabaseClient<*>.executeQuery(query: Query, dataQueryMapper: DataQueryMapper<Data>): RowSet<Data>
Link copied to clipboard
suspend fun <T> DatabaseClient<*>.executeSingleColumnSelectQuery(columnSet: ColumnSet, column: Column<T>, buildQuery: FieldSet.() -> Query): RowSet<T>
inline suspend fun <T, R> DatabaseClient<*>.executeSingleColumnSelectQuery(columnSet: ColumnSet, column: Column<T>, buildQuery: FieldSet.() -> Query, crossinline mapper: T.() -> R): RowSet<R>
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 <Data : Any> DatabaseClient<*>.executeVertxSqlClientRowQuery(query: Query, rowDataQueryMapper: RowDataQueryMapper<Data>): RowSet<Data>
Link copied to clipboard
suspend fun <U> executeWithMapping(statement: Statement<*>, RowMapper: Function<Row, U>): RowSet<U>
Link copied to clipboard
fun <T> exposedTransaction(statement: Transaction.() -> T): T
Link copied to clipboard
fun FieldSet.getFieldExpressionSetWithTransaction(): Set<Expression<*>>
fun Query.getFieldExpressionSetWithTransaction(): Set<Expression<*>>
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.insert(table: T, body: T.(InsertStatement<Number>) -> Unit)
suspend fun <Data : Any> DatabaseClient<*>.insert(table: Table, data: Data, dataUpdateMapper: DataUpdateMapper<Data>)
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.insertIgnore(table: T, body: T.(InsertStatement<Number>) -> Unit): Boolean
suspend fun <Data : Any> DatabaseClient<*>.insertIgnore(table: Table, data: Data, dataUpdateMapper: DataUpdateMapper<Data>): Boolean
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.insertIgnoreSelect(table: T, selectQuery: AbstractQuery<*>, columns: List<Column<*>> = table.defaultColumnsForInsertSelect()): Int
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.insertIgnoreSingle(table: T, body: T.(InsertStatement<Number>) -> Unit): Boolean
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.insertSelect(table: T, selectQuery: AbstractQuery<*>, columns: List<Column<*>> = table.defaultColumnsForInsertSelect()): Int
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.insertSingle(table: T, body: T.(InsertStatement<Number>) -> Unit)
Link copied to clipboard
suspend fun isWorking(): Boolean
Link copied to clipboard
inline suspend fun DatabaseClient<*>.select(columnSet: ColumnSet, buildQuery: ColumnSet.() -> Query): RowSet<ResultRow>
inline suspend fun <Data> DatabaseClient<*>.select(columnSet: ColumnSet, buildQuery: ColumnSet.() -> Query, crossinline resultRowMapper: ResultRow.() -> Data): RowSet<Data>
suspend fun <Data : Any> DatabaseClient<*>.select(columnSet: ColumnSet, dataQueryMapper: DataQueryMapper<Data>, buildQuery: FieldSet.() -> Query): RowSet<Data>
Link copied to clipboard
suspend fun <E> DatabaseClient<*>.selectBatch(fieldSet: FieldSet, buildQuery: FieldSet.(E) -> Query, data: Iterable<E>): Sequence<RowSet<ResultRow>>

This function may be very rarely used, as eq conditions can usually be combined into an inList select query.

Link copied to clipboard
inline suspend fun <T> DatabaseClient<*>.selectExpression(expression: Expression<T>): T

suspend fun <T : Any> DatabaseClient<*>.selectExpression(clazz: KClass<T>, expression: Expression<T?>): T?

SQL: SELECT <expression>;. Example: SELECT EXISTS(<query>).

Link copied to clipboard
suspend fun <T> DatabaseClient<*>.selectSingleColumn(columnSet: ColumnSet, column: Column<T>, buildQuery: FieldSet.() -> Query): RowSet<T>
inline suspend fun <ColumnT, DataT> DatabaseClient<*>.selectSingleColumn(columnSet: ColumnSet, column: Column<ColumnT>, buildQuery: FieldSet.() -> Query, crossinline mapper: ColumnT.() -> DataT): RowSet<DataT>
Link copied to clipboard
suspend fun <T : Comparable<T>> DatabaseClient<*>.selectSingleEntityIdColumn(columnSet: ColumnSet, column: Column<EntityID<T>>, buildQuery: FieldSet.() -> Query): RowSet<T>
Link copied to clipboard
suspend fun <T> DatabaseClient<*>.selectTableExpression(columnSet: ColumnSet, expression: Expression<T>, buildQuery: FieldSet.() -> Query): RowSet<T>

SQL: SELECT <expression> FROM <table>;. Examples: SELECT COUNT(*) FROM <table>;, SELECT SUM(<column>) FROM <table>;.

Link copied to clipboard
suspend fun <T : Table, E, SelectorResultT : Comparable<SelectorResultT>> DatabaseClient<*>.sortDataAndBatchUpdate(table: T, data: Iterable<E>, selector: (E) -> SelectorResultT, where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement, E) -> Unit): Sequence<Int>
Link copied to clipboard
fun Row.toExposedResultRowWithTransaction(query: Query): ResultRow
Link copied to clipboard
suspend fun <T : Table> DatabaseClient<*>.update(table: T, where: BuildWhere? = null, limit: Int? = null, body: T.(UpdateStatement) -> Unit): Int

suspend fun <Data : Any> DatabaseClient<*>.update(table: Table, where: BuildWhere? = null, limit: Int? = null, data: Data, dataUpdateMapper: DataUpdateMapper<Data>): Int

In most cases you should specify the fields to update in a more detailed way instead of using this function.

Link copied to clipboard
suspend fun <T> DatabaseClient<PgPool>.withPgTransaction(function: suspend (DatabaseClient<PgConnection>) -> T): T
Link copied to clipboard
suspend fun <T> DatabaseClient<PgConnection>.withSavepointAndRollbackIfThrows(savepointName: String, function: suspend (DatabaseClient<PgConnection>) -> T): T
Link copied to clipboard
suspend fun DatabaseClient<PgConnection>.withSavepointAndRollbackIfThrowsOrFalse(savepointName: String, function: suspend (DatabaseClient<PgConnection>) -> Boolean): Boolean
Link copied to clipboard
suspend fun <RollbackT, ReleaseT> DatabaseClient<PgConnection>.withSavepointAndRollbackIfThrowsOrLeft(savepointName: String, function: suspend (DatabaseClient<PgConnection>) -> Either<RollbackT, ReleaseT>): Either<RollbackT, ReleaseT>

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

Link copied to clipboard
suspend fun <T> DatabaseClient<PgConnection>.withSavepointAndRollbackIfThrowsOrNone(savepointName: String, function: suspend (DatabaseClient<PgConnection>) -> Option<T>): Option<T>
Link copied to clipboard
suspend fun <T> DatabaseClient<PgPool>.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 <T> DatabaseClient<SqlConnection>.withTransactionCommitOrRollback(function: suspend (DatabaseClient<SqlConnection>) -> Option<T>): Option<T>