update

fun <T : KQLiteTable> T.update(onConflict: Action? = null, connection: SQLiteConnection? = null, binding: Bind.(T) -> Unit): UpdateStatement<T>

Creates an UPDATE statement for the table.

This function initiates a fluent API for constructing and executing an UPDATE statement. It allows for more complex updates involving WHERE clauses, ordering, limits, and conflict resolution. The statement is not executed until UpdateStatement.execute or UpdateStatement.executeReturning is called.

Example

// Update the salary for all employees in the "Sales" department,
// ordered by their hire date, and limit the update to the first 10.
Employees
.update(
onConflict = Action.ROLLBACK,
binding = {
it.salary.bind(it.salary * 1.1) // Give a 10% raise
},
).where {
it.department EQ "Sales"
}.orderBy(
Employees.hireDate,
sort = Sort.DESC,
).limit(10)
.execute()

Return

An UpdateStatement instance that can be further configured and executed.

Author

MOHAMMAD AZIM ANSARI

Parameters

onConflict

An optional Action to specify the conflict resolution strategy (e.g., ROLLBACK, ABORT, IGNORE). Defaults to null (default database behavior).

connection

An optional SQLiteConnection to use for this specific operation. If null, a default connection is used.

binding

A lambda function to define the columns and their new values. The Bind receiver provides a convenient way to pair columns with values (e.g., it.column to "new value").

Type Parameters

T

The type of the KQLiteTable being updated.

See also