Pepperbc
07/04/2020, 3:42 AMEvan R.
07/06/2020, 2:50 PMsetIfNotNull()
extension function on UpdateStatement
then made an “update” function with optional arguments. Here’s the implementation of `setIfNotNull()`:
/**
* Updates the value of a column if and only if the passed value is non-null
*/
fun <T> UpdateStatement.setIfNotNull(column: Column<T>, value: T?) {
if (value != null) {
this[column] = value
}
}
Evan R.
07/06/2020, 2:54 PMfun <T> UpdateStatement.setIfIntentional(column: Column<T?>, update: NullableUpdate<T>) {
if (update.shouldUpdate) {
this[column] = update.newValue
}
}
And the NullableUpdate object:
data class NullableUpdate<T>(val newValue: T?, val shouldUpdate: Boolean = true) {
companion object {
fun <T> doNotUpdate() = NullableUpdate<T>(null, false)
}
}