FetchSpec

interface FetchSpec(source)

Specifies how to execute the built SQL and retrieve the results.

Each terminal operation (singleMap, single, list, rowsUpdated, generatedValues, ...) executes the statement when invoked, except flowMap and flow, which execute it when the returned Flow is collected.

Rows are mapped to the specified type as follows: simple scalar types (numbers, strings, date/time types, ...) are read from the first column of the row, while other types (e.g. data classes) are mapped by matching column names to constructor parameters.

Functions

Link copied to clipboard
abstract fun fetchSize(fetchSize: Int): KueryClient.FetchSpec

Sets the fetch size (the number of rows fetched from the database at a time) to use when executing this query.

Link copied to clipboard
abstract fun <T : Any> flow(returnType: KClass<T>): Flow<T>

Executes the query and emits each row converted to returnType, without accumulating all rows in memory.

Link copied to clipboard
inline fun <T : Any> KueryClient.FetchSpec.flow(): Flow<T>

Executes the query and emits each row converted to T, without accumulating all rows in memory.

Link copied to clipboard
abstract fun flowMap(): Flow<Map<String, Any?>>

Executes the query and emits each row as a map keyed by column name, without accumulating all rows in memory.

Link copied to clipboard
abstract suspend fun generatedValues(vararg columns: String): Map<String, Any>

Executes the statement and returns one row of values generated on the database side, such as an auto-increment ID. The map keys and value types are those reported by the configured driver and may differ from the requested column names.

Link copied to clipboard
abstract suspend fun <T : Any> list(returnType: KClass<T>): List<T>

Executes the query and returns all rows converted to returnType.

Link copied to clipboard
inline suspend fun <T : Any> KueryClient.FetchSpec.list(): List<T>

Executes the query and returns all rows converted to T.

Link copied to clipboard
abstract suspend fun listMap(): List<Map<String, Any?>>

Executes the query and returns all rows as a list of maps keyed by column name.

Link copied to clipboard
abstract suspend fun rowsUpdated(): Long

Executes the statement (typically INSERT, UPDATE, or DELETE) and returns the number of affected rows.

Link copied to clipboard
abstract suspend fun <T : Any> single(returnType: KClass<T>): T

Executes the query and returns exactly one row converted to returnType.

Link copied to clipboard
inline suspend fun <T : Any> KueryClient.FetchSpec.single(): T

Executes the query and returns exactly one row converted to T.

Link copied to clipboard
abstract suspend fun singleMap(): Map<String, Any?>

Executes the query and returns exactly one row as a map keyed by column name.

Link copied to clipboard
abstract suspend fun singleMapOrNull(): Map<String, Any?>?

Executes the query and returns at most one row as a map keyed by column name, or null if the query returns no rows.

Link copied to clipboard
abstract suspend fun <T : Any> singleOrNull(returnType: KClass<T>): T?

Executes the query and returns at most one row converted to returnType, or null if the query returns no rows.

Link copied to clipboard
inline suspend fun <T : Any> KueryClient.FetchSpec.singleOrNull(): T?

Executes the query and returns at most one row converted to T, or null if the query returns no rows.