UpdateQueryBuilder

Defines the public API for building SQL UPDATE queries.

// Promote a legionnaire and record the timestamp
dataAccess.update("legionnaires")
.setValue("rank")
.setExpression("promoted_at", "NOW()")
.where("id = @id")
.returning("*")
.toSingleOf<Legionnaire>("rank" to Rank.Optio, "id" to legionnaireId)

Functions

Link copied to clipboard
abstract fun asStep(): StepBuilderMethods

Converts this builder to a StepBuilderMethods for lazy execution within a TransactionPlan.

Link copied to clipboard
abstract fun copy(): UpdateQueryBuilder

Creates and returns a deep copy of this builder. Useful for creating query variants from a shared base without modifying the original.

Link copied to clipboard
abstract fun execute(params: Map<String, Any?> = emptyMap()): DataResult<Int>

Executes the query and returns the number of rows that were updated

Link copied to clipboard
Link copied to clipboard
abstract fun from(tables: String): UpdateQueryBuilder

Adds a FROM clause to the UPDATE query.

Link copied to clipboard
abstract fun iterate(fetchSize: Int = 100): IterativeTerminalMethods

Switches the builder to iterative mode, optimal for large datasets.

Link copied to clipboard

Configures additional options for this query.

Link copied to clipboard

Marks the WITH clause as recursive.

Link copied to clipboard
abstract fun returning(vararg columns: String): UpdateQueryBuilder

Adds a RETURNING clause. Requires using methods like .toList(), .toSingle(), etc. instead of .execute().

Link copied to clipboard
abstract fun setExpression(column: String, value: String): UpdateQueryBuilder

Defines a single assignment in the SET clause using a raw SQL expression.

Link copied to clipboard

Defines assignments in the SET clause using raw SQL expressions.

Link copied to clipboard
abstract fun setValue(column: String): UpdateQueryBuilder

Defines a single assignment in the SET clause. Automatically generates a placeholder with the key name.

Link copied to clipboard
abstract fun setValues(values: List<String>): UpdateQueryBuilder

Sets values to update. Automatically generates placeholders in @value format for each value in the list.

abstract fun setValues(values: Map<String, Any?>): UpdateQueryBuilder

Sets values to update. Automatically generates placeholders in @key format for each key in the map. Values from the map must be passed in the terminal method (e.g., .execute()).

Link copied to clipboard
abstract fun <T> toColumn(targetType: KType, params: Map<String, Any?> = emptyMap()): DataResult<List<T>>

Fetches a list of values from the first column of all rows. Nullability of elements is determined by the KType: use toColumn<Int>() for non-null or toColumn<Int?>() for nullable elements.

Link copied to clipboard
inline fun <T> TerminalReturningMethods.toColumn(params: Map<String, Any?> = emptyMap()): DataResult<List<T>>
inline fun <T> TerminalReturningMethods.toColumn(vararg params: Pair<String, Any?>): DataResult<List<T>>
Link copied to clipboard
abstract fun <T> toField(targetType: KType, params: Map<String, Any?> = emptyMap()): DataResult<T>

Fetches a single value from the first column of the first row. Nullability is determined by the KType: use toField<Int>() for non-null or toField<Int?>() for nullable results.

Link copied to clipboard
inline fun <T> TerminalReturningMethods.toField(params: Map<String, Any?> = emptyMap()): DataResult<T>
inline fun <T> TerminalReturningMethods.toField(vararg params: Pair<String, Any?>): DataResult<T>
Link copied to clipboard
abstract fun <T> toFieldStrict(targetType: KType, params: Map<String, Any?> = emptyMap()): DataResult<T>

Fetches a single value from the first column of the first row. Always returns Failure if no rows are found, regardless of nullability. Nullability only controls whether a null value in the column is allowed: use toFieldStrict<Int>() to fail on null, or toFieldStrict<Int?>() to allow null values.

Link copied to clipboard
inline fun <T> TerminalReturningMethods.toFieldStrict(params: Map<String, Any?> = emptyMap()): DataResult<T>
Link copied to clipboard
abstract fun toList(params: Map<String, Any?> = emptyMap()): DataResult<List<Map<String, Any?>>>

Fetches a list of rows as List>.

Link copied to clipboard
Link copied to clipboard
abstract fun <T : Any> toListOf(params: Map<String, Any?> = emptyMap(), mapper: DataMapper<T>): DataResult<List<T>>

Maps results to a list of objects using the provided mapper. This bypasses reflection and is the most efficient way to map results to domain objects.

abstract fun <T : Any> toListOf(kType: KType, params: Map<String, Any?> = emptyMap()): DataResult<List<T>>

Maps results to a list of objects of the given type. Requires that column names/aliases in SQL (in snake_case convention) match property names in the target class (in camelCase convention) or have a @MapKey annotation with the stored column name.

Link copied to clipboard
inline fun <T : Any> TerminalReturningMethods.toListOf(params: Map<String, Any?> = emptyMap()): DataResult<List<T>>
inline fun <T : Any> TerminalReturningMethods.toListOf(vararg params: Pair<String, Any?>): DataResult<List<T>>
fun <T : Any> TerminalReturningMethods.toListOf(vararg params: Pair<String, Any?>, mapper: DataMapper<T>): DataResult<List<T>>
Link copied to clipboard
abstract fun toSingle(params: Map<String, Any?> = emptyMap()): DataResult<Map<String, Any?>?>

Fetches a single row as Map?. Returns Success(null) if no rows.

Link copied to clipboard
Link copied to clipboard
abstract fun <T> toSingleOf(kType: KType, params: Map<String, Any?> = emptyMap()): DataResult<T>

Maps the result to a single object of the given type. Works on the same mapping principle as toListOf. Nullability is determined by the KType: use toSingleOf<User>() for non-null or toSingleOf<User?>() for nullable results.

abstract fun <T> toSingleOf(kType: KType, params: Map<String, Any?> = emptyMap(), mapper: DataMapper<T & Any>): DataResult<T>

Maps the result to a single object using the provided mapper. Nullability is determined by the KType: use toSingleOf<User>(mapper) for non-null or toSingleOf<User?>(mapper) for nullable results. This bypasses reflection and is the most efficient way to map results to domain objects.

Link copied to clipboard
inline fun <T> TerminalReturningMethods.toSingleOf(params: Map<String, Any?> = emptyMap()): DataResult<T>
inline fun <T> TerminalReturningMethods.toSingleOf(vararg params: Pair<String, Any?>): DataResult<T>
inline fun <T> TerminalReturningMethods.toSingleOf(params: Map<String, Any?> = emptyMap(), mapper: DataMapper<T & Any>): DataResult<T>
inline fun <T> TerminalReturningMethods.toSingleOf(vararg params: Pair<String, Any?>, mapper: DataMapper<T & Any>): DataResult<T>
Link copied to clipboard
abstract fun toSingleStrict(params: Map<String, Any?> = emptyMap()): DataResult<Map<String, Any?>>

Fetches a single row as Map. Returns Failure if no rows.

Link copied to clipboard
Link copied to clipboard
abstract fun toSql(): String

Returns the SQL string without executing the query.

Link copied to clipboard
abstract fun where(condition: String): UpdateQueryBuilder

Defines the WHERE condition. The clause is mandatory for security reasons.

Link copied to clipboard
abstract fun with(name: String, query: String): UpdateQueryBuilder

Adds a Common Table Expression (CTE) to the query.