StepBuilder

class StepBuilder @PublishedApi constructor(val query: RunnableQuery<*>)

Turns a query into a step instead of running it.

The terminals here are the ones that make sense for something whose result is stored and referred to later: the fetch* family and update. The forEach* family is absent on purpose - a plan keeps every result so that later steps can use it, and a walk over rows too large to hold has nothing to keep. So is RawQuery.execute, reachable though it is on a raw query: it speaks a protocol that binds nothing, so a step made of one could take no TransactionValue and could therefore refer to no earlier step, which is the only thing a step does that a lambda does not. DDL and SET belong in a query run on the transaction's own session; the timeouts worth setting are properties of TransactionDefinition already.

Parameters may hold TransactionValues among ordinary values, and only those are resolved. A SpreadParameters goes among them too, and fills its slot with a row's worth of parameters rather than with one.

val edictId = plan.add(
db.insertInto("edicts").values(edict).returning("id")
.asStep().fetchFieldStrict<Int>(edict)
)

for (item in levy) {
plan.add(
db.insertInto("edict_items").values(listOf("edict_id", "province_id", "amount"))
.asStep().update(
"edict_id" to edictId.value(),
"province_id" to item.provinceId,
"amount" to item.amount
)
)
}

Constructors

Link copied to clipboard
internal constructor(query: RunnableQuery<*>)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
inline fun <T> fetchField(params: Map<String, Any?> = emptyMap()): TransactionStep<T>
inline fun <T> fetchField(vararg params: Pair<String, Any?>): TransactionStep<T>

A step that returns the first column of one row as T.

Link copied to clipboard
inline fun <T> fetchFields(params: Map<String, Any?> = emptyMap()): TransactionStep<List<T>>
inline fun <T> fetchFields(vararg params: Pair<String, Any?>): TransactionStep<List<T>>

A step that returns the first column of every row as T.

Link copied to clipboard
inline fun <T> fetchFieldStrict(params: Map<String, Any?> = emptyMap()): TransactionStep<T>
inline fun <T> fetchFieldStrict(vararg params: Pair<String, Any?>): TransactionStep<T>

As fetchField, but the step's query must return exactly one row.

Link copied to clipboard
inline fun <T : Any> fetchObject(params: Map<String, Any?> = emptyMap()): TransactionStep<T?>
inline fun <T : Any> fetchObject(vararg params: Pair<String, Any?>): TransactionStep<T?>

A step that maps one row onto T, or null where none matched.

Link copied to clipboard
inline fun <T : Any> fetchObjects(params: Map<String, Any?> = emptyMap()): TransactionStep<List<T>>
inline fun <T : Any> fetchObjects(vararg params: Pair<String, Any?>): TransactionStep<List<T>>

A step that maps every row onto T.

Link copied to clipboard
inline fun <T : Any> fetchObjectStrict(params: Map<String, Any?> = emptyMap()): TransactionStep<T>
inline fun <T : Any> fetchObjectStrict(vararg params: Pair<String, Any?>): TransactionStep<T>

A step that maps one row onto T and fails where the count was anything but one.

Link copied to clipboard
fun fetchRow(params: Map<String, Any?> = emptyMap()): TransactionStep<Row?>
fun fetchRow(vararg params: Pair<String, Any?>): TransactionStep<Row?>

A step that returns one row, or null where none matched.

Link copied to clipboard
fun fetchRows(params: Map<String, Any?> = emptyMap()): TransactionStep<List<Row>>
fun fetchRows(vararg params: Pair<String, Any?>): TransactionStep<List<Row>>

A step that returns every row.

Link copied to clipboard
fun fetchRowStrict(params: Map<String, Any?> = emptyMap()): TransactionStep<Row>
fun fetchRowStrict(vararg params: Pair<String, Any?>): TransactionStep<Row>

A step that returns one row and fails where the count was anything but one.

Link copied to clipboard
fun update(params: Map<String, Any?> = emptyMap()): TransactionStep<Long>
fun update(vararg params: Pair<String, Any?>): TransactionStep<Long>

A step that runs the statement and returns how many rows it affected.