What Kotlin feature is used for ``` object Users :...
# announcements
r
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? from https://github.com/JetBrains/Exposed
r
maybe ask in #C0CG7E0A1 but it looks like
.insert
is an extension function and then
id
,
name
and
cityId
are just
Column
instances given to the
InsertStatement
and
val title: Column<?>
just doesn’t exists in your
Users
object
r
but how it knows that columns are from
Users
and not from other
object
?
r
because
.insert
is added to
Users
Copy code
fun <T:Table> T.insert(body: T.(InsertStatement<Number>)->Unit): InsertStatement<Number> = InsertStatement<Number>(this).apply {
    body(this)
    execute(TransactionManager.current())
}
T
is a specific type
again, I am new to Kotlin. ask in #C0CG7E0A1 🙂
r
ok, thanks
m
@rrader
insert
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