A member extension function belongs to one class while extending another receiver type. This combines the containing class’s context with the receiver’s API, making it useful for readable internal DSLs. section 13.4.3
class Table {
fun Column<Int>.autoIncrement(): Column<Int> #1
// ...
}
Exposed declares autoIncrement as a member of Table and an extension on Column<Int>, then chains it after integer("id"). section 13.4.3
The declaration gives the function two useful contexts:
- Table supplies the containing-class context used by the SQL table DSL. section 13.4.3
- Column<Int> becomes the extension receiver, so autoIncrement can be called directly on an integer column. section 13.4.3
- Returning the same column enables declarations such as val id = integer("id").autoIncrement(). section 13.4.3
Table declaration
object Country : Table() { val id = integer("id").autoIncrement() val name = varchar("name", 50) override val primaryKey = PrimaryKey(id) } The declaration describes a database table; Exposed can create it through SchemaUtils.create(Country) inside a transaction.
