https://kotlinlang.org logo
#exposed
Title
# exposed
r

rrader

12/19/2018, 10:15 AM
What Kotlin feature is used for
Copy code
object Users : Table() {
    val id = varchar("id", 10).primaryKey() // Column<String>
    val name = varchar("name", length = 50) // Column<String>
    val cityId = (integer("city_id") references Cities.id).nullable() // Column<Int?>
}
Users.insert {
            it[id] = "andrey"
            it[name] = "Andrey"
            it[cityId] = saintPetersburgId
        }
how compiler know that
it[id]
is valid and for example
it[title]
is not valid?
a

Alexander

12/19/2018, 10:23 AM
It's due to a closure that passed into
insert
is defined like:
Copy code
body: T.(InsertStatement<Number>) -> Unit
where
T: Table
Thus all properties of the
Users
table are available inside the closure.
4 Views