rrader
12/19/2018, 10:23 AMobject 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?
from https://github.com/JetBrains/Exposedreik.schatz
12/19/2018, 11:00 AM.insert is an extension function and then id, name and cityId are just Column instances given to the InsertStatementreik.schatz
12/19/2018, 11:02 AMval title: Column<?> just doesn’t exists in your Users objectrrader
12/19/2018, 11:03 AMUsers and not from other object ?reik.schatz
12/19/2018, 11:06 AM.insert is added to Usersreik.schatz
12/19/2018, 11:06 AMfun <T:Table> T.insert(body: T.(InsertStatement<Number>)->Unit): InsertStatement<Number> = InsertStatement<Number>(this).apply {
body(this)
execute(TransactionManager.current())
}reik.schatz
12/19/2018, 11:07 AMT is a specific typereik.schatz
12/19/2018, 11:08 AMrrader
12/19/2018, 11:45 AMMike
12/19/2018, 1:48 PMinsert is an extension function on all types. body is a Lambda with receiver. Some more advanced Kotlin features that allow for powerful DSL’s.
Hopefully those keywords give you some direction for research.
But ultimately, the Lambda you’re passing to insert (everything inside the {}) has a single parameter it that is of the type of the class insert is being called on.
So in this case, the compiler knows that it is of type Users