English | 简体中文

api-docs / org.ktorm.schema / Table / <init>

<init>

Table(
    tableName: String,
    alias: String? = null,
    catalog: String? = null,
    schema: String? = null,
    entityClass: KClass<E>? = null)

Base class of Ktorm’s table objects. This class extends from BaseTable, additionally providing a binding mechanism
with Entity interfaces based on functions such as bindTo, references.

Table implements the doCreateEntity function from the parent class. The function automatically creates an
entity object using the binding configuration specified by bindTo and references, reading columns’ values from
the result set and filling them into corresponding entity properties.

To use this class, we need to define our entities as interfaces extending from Entity. Here is an example. More
documents can be found at https://www.ktorm.org/en/entities-and-column-binding.html

interface Department : Entity<Department> {
val id: Int
var name: String
var location: String
}
object Departments : Table<Department>("t_department") {
val id = int("id").primaryKey().bindTo { it.id }
val name = varchar("name").bindTo { it.name }
val location = varchar("location").bindTo { it.location }
}