Exposed
Exposed copied to clipboard
Read-only columns support
By read-only I mean columns that generated/updated by database( for example ON UPDATE for mysql, or generated column, or modified by trigger). Such columns should not be used in update queries.
How about such syntax:
object ConfigTable : IntIdTable() {
val key = varchar("name", 255)
val value = varchar("value", 255)
val created = readonly(datetime("created"))
val modified = readonly(timestamp("modified"))
}
And for entities all fields that referenced by readonly table-fields can only be val:
class ConfigEntity(id: EntityID<Int>) : IntEntity(id) {
var key by ConfigTable.key
var value by ConfigTable.value
// OK
val created by ConfigTable.created
// Compile-time error
var modified by ConfigTable.modified
companion object : IntEntityClass<ConfigEntity>(ConfigTable)
}
Any updates on this @Tapac? Has anybody found a workaround for adding this?
It feasible by declaring your own StatementInterceptor where you will check that some columns are absent from UpdateStatement
We managed to use something like this:
object ConfigTable : IntIdTable() {
val key = varchar("name", 255)
val value = varchar("value", 255)
val created = datetime("created")
val modified = timestamp("modified")
}
class ConfigEntity(id: EntityID<Int>) : IntEntity(id) {
var key by ConfigTable.key
var value by ConfigTable.value
val created: LocalDateTime
get() = _created!!
val modified: Instant
get() = _modified!!
private val _created by ConfigTable.created.nullable()
private val _modified by ConfigTable.modified.nullable()
companion object : IntEntityClass<ConfigEntity>(ConfigTable)
}
Since version 0.44.0, a column can be flagged as generated/updated by the database using Column.databaseGenerated().