SuspendExecutable

interface SuspendExecutable<out T, S : Statement<T>>

Executable provides a customizable execution mechanism for SQL statements within a transaction.

This interface allows implementing classes to define specific execution logic specific to R2DBC and customize how the return value is handled. It is primarily used when fine-grained control over statement execution is required.

For the blocking JDBC alternative of this interface, see BlockingExecutable.

Usage Example:

open class BatchUpsertSuspendExecutable(
    override val statement: BatchUpsertStatement
) : BatchInsertSuspendExecutable<BatchUpsertStatement>(statement) {
    override suspend fun prepared(transaction: R2dbcTransaction, sql: String): R2dbcPreparedStatementApi {
        // We must return values from upsert because returned id could be different depending on insert or upsert happened
        if (!currentDialect.supportsOnlyIdentifiersInGeneratedKeys) {
            return transaction.connection.prepareStatement(sql, statement.shouldReturnGeneratedValues)
        }

        return super.prepared(transaction, sql)
    }
}

The implemented Executable can be later used in the utility functions like Table.batchUpsert.

Parameters

T

The return type of the SQL execution result.

S

The type of SQL statement that is executed.

Inheritors

Properties

Link copied to clipboard

Whether the SQL statement is meant to be performed as part of a batch execution.

Link copied to clipboard
abstract val statement: S

Functions

Link copied to clipboard
open suspend fun execute(transaction: R2dbcTransaction): T?

Executes the SQL statement directly in the provided transaction and returns the generated result, or null if either no result was retrieved or if the transaction blocked statement execution.

Link copied to clipboard
abstract suspend fun R2dbcPreparedStatementApi.executeInternal(transaction: R2dbcTransaction): T?

Determines the exact way that an SQL statement is executed in a transaction and applies any necessary logic before returning the result generated by the executed statement.

Link copied to clipboard
open suspend fun prepared(transaction: R2dbcTransaction, sql: String): R2dbcPreparedStatementApi

Uses a transaction connection and an sql string representation to return a precompiled SQL statement, stored as an implementation of PreparedStatementApi.