com.sxtanna.db.struct.statement.update.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Kuery Show documentation
Show all versions of Kuery Show documentation
MySQL Kotlin DSL/ORM based on HikariCP
package com.sxtanna.db.struct.statement
import com.sxtanna.db.ext.Value
import com.sxtanna.db.struct.Table
import com.sxtanna.db.type.Executed
import com.sxtanna.db.type.Targeted
import kotlin.reflect.KProperty1
/**
* Describes an SQL "UPDATE" statement
*/
interface Update : Executed, Targeted, E> {
/**
* Set this column to this value
*/
fun set(column : KProperty1, value : R) : Update
}
/**
* An object that can update rows and columns in a table
*/
interface Updater {
/**
* Create an update statement for this table
* * Execute statement either by calling [Update.execute]
* * or
* * Returning it from a Kuery#invoke block
*/
fun update(table : Table) : Update
/**
* Update the supplied rows in this table
* * Executed automatically
*/
fun update(table : Table, vararg rows : E) {
update(table, rows.toList())
}
/**
* Update the supplied rows in this table
* * Executed automatically
*/
fun update(table : Table, rows : Collection)
/**
* Create an update statement that updates the supplied columns in this table
* * Execute statement either by calling [Update.execute]
* * or
* * Returning it from a Kuery#invoke block
*/
fun update(table : Table, vararg values : Value) : Update {
val update = update(table)
values.forEach { update.set(it.prop, it.value) }
return update
}
/**
* Update all rows in this table to this row
* * Executed automatically
* * Does not work on tables with primary keys
*/
fun updateAllRows(table : Table, row : E)
/**
* Update all rows in this table to these values
* * Executed automatically
* * Cannot set the value of a primary key
*/
fun updateAllRows(table : Table, vararg values : Value)
/**
* An object that can update rows and columns in its table
*/
interface TableUpdater {
/**
* @see [Updater.update]
*/
fun update() : Update
/**
* Updater.update(table : Table<E>, vararg rows : E)
*
* @sample [Cannot_link_to_specific_method][update]
*/
fun update(vararg rows : E) {
update(rows.toList())
}
/**
* Updater.update(table : Table, rows : Collection)
*
* @sample [Cannot_link_to_specific_method][update]
*/
fun update(rows : Collection)
/**
* Updater.update(table : Table<E>, vararg values : Value<E, *>)
*
* @sample [Cannot_link_to_specific_method][update]
*/
fun update(vararg values : Value) : Update
/**
* @see [Updater.updateAllRows]
*/
fun updateAllRows(row : E)
/**
* Updater.updateAllRows(table : Table<E>, vararg values : Value<E, *>)
*
* @sample [Cannot_link_to_specific_method][updateAllRows]
*/
fun updateAllRows(vararg values : Value)
}
}