BaseTable
Base class of Ktorm's table objects, represents relational tables in the database.
This class provides the basic ability of table and column definition but doesn't support any binding mechanisms. If you need the binding support to Entity interfaces, use Table instead.
There is an abstract function doCreateEntity. Subclasses should implement this function, creating an entity object from the result set returned by a query, using the binding rules defined by themselves. Here, the type of the entity object could be an interface extending from Entity, or a data class, POJO, or any kind of classes.
Here is an example defining an entity as data class. The full documentation can be found at: https://www.ktorm.org/en/define-entities-as-any-kind-of-classes.html
data class Staff(
val id: Int,
val name: String,
val job: String,
val hireDate: LocalDate
)
object Staffs : BaseTable<Staff>("t_employee") {
val id = int("id").primaryKey()
val name = varchar("name")
val job = varchar("job")
val hireDate = date("hire_date")
override fun doCreateEntity(row: QueryRowSet, withReferences: Boolean) = Staff(
id = row[id] ?: 0,
name = row[name].orEmpty(),
job = row[job].orEmpty(),
hireDate = row[hireDate] ?: LocalDate.now()
)
}
Since
2.5
Inheritors
Constructors
Properties
Functions
Convert this table to a TableExpression.
Create an entity object from the specific row of query results. This function uses the binding configurations of the table, filling column values into corresponding properties of the returned entity.
Define a column typed of LocalDateTimeSqlType.
Define a column typed of DecimalSqlType.
Define a column typed of TimestampSqlType.