ru.astrainteractive.astralibs.orm.database.Entity.kt Maven / Gradle / Ivy
package ru.astrainteractive.astralibs.orm.database
import kotlin.reflect.KProperty
abstract class Entity(val table: Table) {
private val writeValues = LinkedHashMap, Any?>()
operator fun Column.getValue(o: Entity, desc: KProperty<*>): K {
return writeValues[this as Column] as K
}
operator fun Column.setValue(o: Entity, desc: KProperty<*>, value: K) {
check(table.columns.contains(this)) {
"Table ${table.tableName} does not contains column named ${this.name}"
}
writeValues[this as Column] = value
}
operator fun set(column: Column, value: Any?) {
check(table.columns.contains(column)) {
"Table ${table.tableName} does not contains column named ${column.name}"
}
writeValues[column] = value
}
operator fun get(column: Column): K {
return writeValues[column as Column] as K
}
}