api-docs / org.ktorm.schema / BaseTable
BaseTable
abstract class BaseTable<E : Any> : TypeReference<E>
(source code)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
Constructors
Name | Summary |
---|---|
BaseTable( Base class of Ktorm’s table objects, represents relational tables in the database. |
Properties
Name | Summary |
---|---|
val alias: String? The table’s alias. | |
val catalog: String? The table’s catalog. | |
Return all columns of the table. | |
The entity class this table is bound to. | |
The primary key columns of this table. | |
val schema: String? The table’s schema. | |
val tableName: String The table’s name. |
Inherited Properties
Name | Summary |
---|---|
val referencedKotlinType: KType The actual kotlin type argument of subclass without erased. | |
val referencedType: Type The actual type argument of subclass without erased. |
Functions
Name | Summary |
---|---|
Return a new-created table object with all properties (including the table name and columns and so on) being | |
fun asExpression(): TableExpression Convert this table to a TableExpression. | |
Copy column definitions from src to this table. | |
fun createEntity( Create an entity object from the specific row of query results. This function uses the binding configurations | |
abstract fun doCreateEntity( Create an entity object from the specific row of query results. | |
Indicates whether some other object is “equal to” this table. | |
Obtain a column from this table by the name. | |
fun hashCode(): Int Return a hash code value for this table. | |
Mark the registered column as a primary key. | |
Register a column to this table with the given name and sqlType. | |
open fun toString(): String Return a string representation of this table. | |
fun <C : Any, R : Any> Column<C>.transform( Transform the registered column’s SqlType to another. The transformed SqlType has the same |
Extension Functions
Name | Summary |
---|---|
Check if all the records in the table matches the given predicate. | |
Check if there is any record in the table. Check if there is any record in the table matches the given predicate. | |
Create an EntitySequence from this table. | |
Return the average value of the given column or expression of all the records, null if there are no records. | |
Construct insert expressions in the given closure, then batch execute them and return the effected | |
Construct update expressions in the given closure, then batch execute them and return the effected | |
Define a column typed of BlobSqlType. | |
Define a column typed of BooleanSqlType. | |
Construct a bulk insert expression in the given closure, then execute it and return the effected row count. | |
Construct a bulk insert expression in the given closure, then execute it and return the | |
fun <T : BaseTable<*>> T. Bulk insert records to the table, determining if there is a key conflict while inserting each of them, | |
fun <T : BaseTable<*>> T. Bulk insert records to the table, determining if there is a key conflict while inserting each of them, | |
Define a column typed of BytesSqlType. | |
Return the records count in the table. Return the records count in the table that matches the given predicate. | |
fun BaseTable<*>. Join the right table and return a new QuerySource, translated to | |
Define a column typed CubeSqlType. | |
Define a column typed of LocalDateSqlType. | |
fun BaseTable<*>.datetime( Define a column typed of LocalDateTimeSqlType. | |
fun BaseTable<*>.datetimeoffset( Define a column typed of DateTimeOffsetSqlType. | |
fun BaseTable<*>.decimal(name: String): Column<BigDecimal> Define a column typed of DecimalSqlType. | |
Delete the records in the table that matches the given predicate. | |
Delete all the records in the table. | |
Define a column typed of DoubleSqlType. | |
Define a column typed EarthSqlType. | |
Define a column typed of EnumSqlType. | |
infix fun <T : Any> T.eq( Equal operator, translated to | |
Obtain all the entity objects from this table, auto left joining all the reference tables. | |
Obtain a list of entity objects matching the given predicate, auto left joining all the reference tables. | |
Obtain an entity object matching the given predicate, auto left joining all the reference tables. | |
Define a column typed of FloatSqlType. | |
Define a column typed HStoreSqlType. | |
fun BaseTable<*>. Join the right table and return a new QuerySource, translated to | |
Construct an insert expression in the given closure, then execute it and return the effected row count. | |
Construct an insert expression in the given closure, then execute it and return the auto-generated key. | |
Insert a record to the table, determining if there is a key conflict while it’s being inserted, and automatically | |
Insert a record to the table, determining if there is a key conflict while it’s being inserted, and automatically | |
Define a column typed of IntSqlType. | |
Return | |
Return | |
Define a column typed of DateSqlType. | |
Define a column typed of TimeSqlType. | |
Define a column typed of TimestampSqlType. | |
Return a new-created Query object, left joining all the reference tables, and selecting all columns of them. | |
fun <C : Any> BaseTable<*>.json( Define a column typed of JsonSqlType. | |
fun BaseTable<*>. Join the right table and return a new QuerySource, translated to | |
Define a column typed of LongSqlType. | |
fun <E : Any, T : BaseTable<E>, C : Comparable<C>> T. Return the max value of the given column or expression of all the records, null if there are no records in the table. | |
fun <E : Any, T : BaseTable<E>, C : Comparable<C>> T. Return the min value of the given column or expression of all the records, null if there are no records in the table. | |
Define a column typed of MonthDaySqlType, instances of MonthDay are saved as strings in format | |
fun BaseTable<*>. Join the right table and return a new QuerySource, translated to | |
infix fun <T : Any> T.neq( Not-equal operator, translated to | |
Return Return | |
infix fun <T : Any> T.notEq( Not-equal operator, translated to | |
fun BaseTable<*>. Join the right table and return a new QuerySource, translated to | |
fun BaseTable<*>. fun BaseTable<*>. Create a query object, selecting the specific columns or expressions from this table. | |
fun BaseTable<*>. fun BaseTable<*>. Create a query object, selecting the specific columns or expressions from this table distinctly. | |
Define a column typed of ShortSqlType. | |
Return the sum of the given column or expression of all the records, null if there are no records in the table. | |
Define a column typed of TextSqlType. | |
Define a column typed TextArraySqlType. | |
Define a column typed of LocalTimeSqlType. | |
Define a column typed of InstantSqlType. | |
Construct an update expression in the given closure, then execute it and return the effected row count. | |
Define a column typed of UuidSqlType. | |
Define a column typed of VarcharSqlType. | |
Define a column typed of YearSqlType, instances of Year are saved as integers. | |
Define a column typed of YearMonthSqlType, instances of YearMonth are saved as strings in format |
Inheritors
Name | Summary |
---|---|
Base class of Ktorm’s table objects. This class extends from BaseTable, additionally providing a binding mechanism |