api-docs / org.ktorm.schema / Table
Table
open class Table<E : Entity<E>> : BaseTable<E>
(source code)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 }
}
Constructors
Name | Summary |
---|---|
Table( Base class of Ktorm’s table objects. This class extends from BaseTable, additionally providing a binding mechanism |
Inherited 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. |
Functions
Name | Summary |
---|---|
Return a new-created table object with all properties (including the table name and columns and so on) being | |
Bind the column to nested properties, eg. | |
fun doCreateEntity( Create an entity object from the specific row of query results. | |
fun <C : Any, R : Entity<R>> Column<C>.references( Bind the column to a reference table, equivalent to a foreign key in relational databases. |
Inherited Functions
Name | Summary |
---|---|
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 | |
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 |
---|---|
Insert the given entity into this sequence and return the affected record number. | |
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. | |
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 | |
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. | |
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. | |
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 | |
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. | |
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. | |
Update properties of the given entity to the database and return the affected record number. | |
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 |