Table

open class Table(name: String = "") : ColumnSet, DdlAware

Base class for any simple table.

If you want to reference your table use IdTable instead.

Parameters

name

Table name, by default name will be resolved from a class name with "Table" suffix removed (if present)

Inheritors

Constructors

Link copied to clipboard
constructor(name: String = "")

Types

Link copied to clipboard
object Dual : Table

Represents a special dummy DUAL table that is accessible by all users.

Link copied to clipboard
inner class PrimaryKey(val columns: Array<Column<*>>, name: String? = null)

Represents a primary key composed by the specified columns, and with the specified name. If no name is specified, the table name with the "pk_" prefix will be used instead.

Properties

Link copied to clipboard

Returns the first auto-increment column on the table.

Link copied to clipboard
open override val columns: List<Column<*>>

Returns all the columns defined on the table.

Link copied to clipboard
open val ddl: List<String>

Returns the list of DDL statements that create this DdlAware instance.

Link copied to clipboard
open override val fields: List<Expression<*>>

Returns the field of this field set.

Link copied to clipboard

Returns all foreign key constraints declared on the table.

Link copied to clipboard

Returns all indices declared on the table.

Link copied to clipboard
open val primaryKey: Table.PrimaryKey? = null

Returns the primary key of the table if present, null otherwise.

Link copied to clipboard
open val realFields: List<Expression<*>>

Returns all real fields, unrolling composite CompositeColumn if present

Link copied to clipboard

Returns the schema name, or null if one does not exist for this table.

Link copied to clipboard

Returns all sequences declared on the table, along with any auto-generated sequences that are not explicitly declared by the user but associated with the table.

Link copied to clipboard
open override val source: ColumnSet

Return the column set that contains this field set.

Link copied to clipboard
open val tableName: String

Returns the table name.

Functions

Link copied to clipboard
inline fun <E : Any> array(name: String, maximumCardinality: Int? = null): Column<List<E>>

Creates an array column, with the specified name, for storing elements of a List.

fun <E> array(name: String, columnType: ColumnType<E & Any>, maximumCardinality: Int? = null): Column<List<E>>

Creates an array column, with the specified name, for storing elements of a List using a base columnType.

Link copied to clipboard

UUID column will auto generate its value on a client side just before an insert.

Link copied to clipboard
fun <N : Comparable<N>> Column<EntityID<N>>.autoinc(idSeqName: String? = null): Column<EntityID<N>>

Make @receiver column an auto-increment column to generate its values in a database. Note: Only integer and long columns are supported (signed and unsigned types). Some databases, like PostgreSQL, support auto-increment via sequences. In this case a name should be provided using the idSeqName param and Exposed will create a sequence. If a sequence already exists in the database just use its name in idSeqName.

Link copied to clipboard
fun <N : Any> Column<N>.autoIncrement(idSeqName: String? = null): Column<N>

Make @receiver column an auto-increment column to generate its values in a database. Note: Only integer and long columns are supported (signed and unsigned types). Some databases, like PostgreSQL, support auto-increment via sequences. In this case a name should be provided using the idSeqName param and Exposed will create a sequence. If a sequence already exists in the database just use its name in idSeqName.

fun <N : Any> Column<N>.autoIncrement(sequence: Sequence): Column<N>

Make @receiver column an auto-increment column to generate its values in a database. Note: Only integer and long columns are supported (signed and unsigned types). Some databases, like PostgreSQL, support auto-increment via sequences. In this case, a sequence should be provided using the sequence param.

Link copied to clipboard

Creates a binary column, with the specified name, for storing byte arrays of arbitrary size.

fun binary(name: String, length: Int): Column<ByteArray>

Creates a binary column, with the specified name, for storing byte arrays with the specified maximum length.

Link copied to clipboard
fun blob(name: String, useObjectIdentifier: Boolean = false): Column<ExposedBlob>

Creates a binary column, with the specified name, for storing BLOBs. If useObjectIdentifier is true, then the column will use the OID type on PostgreSQL for storing large binary objects. The parameter must not be true for other databases.

Link copied to clipboard
fun bool(name: String): Column<Boolean>

Creates a column, with the specified name, for storing boolean values.

Link copied to clipboard
fun byte(name: String): Column<Byte>

Creates a numeric column, with the specified name, for storing 1-byte integers.

Link copied to clipboard
fun char(name: String): Column<Char>

Creates a character column, with the specified name, for storing single characters.

fun char(name: String, length: Int, collate: String? = null): Column<String>

Creates a character column, with the specified name, for storing strings with the specified length using the specified text collate type. If no collate type is specified then the database default is used.

Link copied to clipboard
fun check(name: String = "", op: SqlExpressionBuilder.() -> Op<Boolean>)

Creates a check constraint in this table.

fun <T> Column<T>.check(name: String = "", op: SqlExpressionBuilder.(Column<T>) -> Op<Boolean>): Column<T>

Creates a check constraint in this column.

Link copied to clipboard
fun <T> Column<T>.clientDefault(defaultValue: () -> T): Column<T>

Sets the default value for this column in the client side.

Link copied to clipboard
open override fun createStatement(): List<String>

Returns the list of DDL statements that create this object.

Link copied to clipboard
open infix override fun crossJoin(otherTable: ColumnSet): Join

Creates a cross join relation with otherTable.

Link copied to clipboard
fun <T : Enum<T>> customEnumeration(name: String, sql: String? = null, fromDb: (Any) -> T, toDb: (T) -> Any): Column<T>

Creates an enumeration column, with the custom SQL type sql, for storing enums of type T using this database-specific type.

Link copied to clipboard

Marks a column as databaseGenerated if the default value of the column is not known at the time of table creation and/or if it depends on other columns. It makes it possible to omit setting it when inserting a new record, without getting an error. The value for the column can be set by creating a TRIGGER or with a DEFAULT clause or by using GENERATED ALWAYS AS via Column.withDefinition, for example.

Link copied to clipboard
fun decimal(name: String, precision: Int, scale: Int): Column<BigDecimal>

Creates a numeric column, with the specified name, for storing numbers with the specified precision and scale.

Link copied to clipboard
fun <T> Column<T>.default(defaultValue: T): Column<T>
fun <T> CompositeColumn<T>.default(defaultValue: T): CompositeColumn<T>

Sets the default value for this column in the database side.

Link copied to clipboard
fun <T> Column<T>.defaultExpression(defaultValue: Expression<T>): Column<T>

Sets the default value for this column in the database side.

Link copied to clipboard

Represents the SQL statement that deletes all rows in a table.

Link copied to clipboard
open override fun describe(s: Transaction, queryBuilder: QueryBuilder)

Appends the SQL representation of this column set to the specified queryBuilder.

Link copied to clipboard
fun double(name: String): Column<Double>

Creates a numeric column, with the specified name, for storing 8-byte (double precision) floating-point numbers.

Link copied to clipboard
open override fun dropStatement(): List<String>

Returns the list of DDL statements that drops this object.

Link copied to clipboard

Converts the @receiver column to an EntityID column.

fun <ID : Comparable<ID>> entityId(name: String, table: IdTable<ID>): Column<EntityID<ID>>

Creates an EntityID column, with the specified name, for storing the identifier of the specified table.

fun <ID : Comparable<ID>> entityId(name: String, originalColumn: Column<ID>): Column<EntityID<ID>>

Creates an EntityID column, with the specified name, for storing the same objects as the specified originalColumn.

Link copied to clipboard
inline fun <T : Enum<T>> enumeration(name: String): Column<T>

Creates an enumeration column, with the specified name, for storing enums of type T by their ordinal.

fun <T : Enum<T>> enumeration(name: String, klass: KClass<T>): Column<T>

Creates an enumeration column, with the specified name, for storing enums of type klass by their ordinal.

Link copied to clipboard
inline fun <T : Enum<T>> enumerationByName(name: String, length: Int): Column<T>

Creates an enumeration column, with the specified name, for storing enums of type T by their name. With the specified maximum length for each name value.

fun <T : Enum<T>> enumerationByName(name: String, length: Int, klass: KClass<T>): Column<T>

Creates an enumeration column, with the specified name, for storing enums of type klass by their name. With the specified maximum length for each name value.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard

Returns whether this table exists in the database.

Link copied to clipboard
fun float(name: String): Column<Float>

Creates a numeric column, with the specified name, for storing 4-byte (single precision) floating-point numbers.

Link copied to clipboard
fun foreignKey(vararg references: Pair<Column<*>, Column<*>>, onUpdate: ReferenceOption? = null, onDelete: ReferenceOption? = null, name: String? = null)
fun foreignKey(vararg from: Column<*>, target: Table.PrimaryKey, onUpdate: ReferenceOption? = null, onDelete: ReferenceOption? = null, name: String? = null)

Creates a composite foreign key.

Link copied to clipboard
open infix override fun fullJoin(otherTable: ColumnSet): Join

Creates a full outer join relation with otherTable.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun index(isUnique: Boolean = false, vararg columns: Column<*>)
fun index(customIndexName: String? = null, isUnique: Boolean = false, vararg columns: Column<*>, functions: List<ExpressionWithColumnType<*>>? = null, indexType: String? = null, filterCondition: FilterCondition = null)

Creates an index.

fun <T> Column<T>.index(customIndexName: String? = null, isUnique: Boolean = false): Column<T>

Creates an index composed by this column only.

Link copied to clipboard
open infix override fun innerJoin(otherTable: ColumnSet): Join

Creates an inner join relation with otherTable.

Link copied to clipboard
fun integer(name: String): Column<Int>

Creates a numeric column, with the specified name, for storing 4-byte integers.

Link copied to clipboard
open override fun join(otherTable: ColumnSet, joinType: JoinType, onColumn: Expression<*>?, otherColumn: Expression<*>?, lateral: Boolean, additionalConstraint: SqlExpressionBuilder.() -> Op<Boolean>?): Join

Creates a join relation with otherTable. When all joining options are absent Exposed will try to resolve referencing columns by itself.

Link copied to clipboard
fun Table.joinQuery(on: SqlExpressionBuilder.(QueryAlias) -> Op<Boolean>? = null, joinType: JoinType = JoinType.INNER, lateral: Boolean = false, joinPart: () -> AbstractQuery<*>): Join

Creates a join relation between this table and a query.

Link copied to clipboard
fun largeText(name: String, collate: String? = null, eagerLoading: Boolean = false): Column<String>

Creates a character column, with the specified name, for storing strings of large length using the specified collate type. If no collated type is specified, then the database default is used.

Link copied to clipboard
open infix override fun leftJoin(otherTable: ColumnSet): Join

Creates a left outer join relation with otherTable.

Link copied to clipboard
fun long(name: String): Column<Long>

Creates a numeric column, with the specified name, for storing 8-byte integers.

Link copied to clipboard
fun mediumText(name: String, collate: String? = null, eagerLoading: Boolean = false): Column<String>

Creates a character column, with the specified name, for storing strings of medium length using the specified collate type. If no collated type is specified, then the database default is used.

Link copied to clipboard
open override fun modifyStatement(): List<String>

Returns the list of DDL statements that modify this object.

Link copied to clipboard

Returns the table name in proper case. Should be called within transaction or default tableName will be returned.

Link copied to clipboard

Returns the table name, without schema and in proper case, with wrapping single- and double-quotation characters removed.

Link copied to clipboard

Marks this CompositeColumn as nullable.

fun <T : Any> Column<T>.nullable(): Column<T?>

Marks this column as nullable.

Link copied to clipboard
@JvmName(name = "nullTransform")
fun <Unwrapped : Any, Wrapped : Any> Column<Unwrapped>.nullTransform(wrap: (Unwrapped) -> Wrapped?, unwrap: (Wrapped?) -> Unwrapped): Column<Wrapped?>

Applies a special transformation that allows a non-nullable database column to accept and/or return values as null on the client side.

Link copied to clipboard
fun <T : Comparable<T>> optReference(name: String, foreign: IdTable<T>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<EntityID<T>?>

Creates a column with the specified name with an optional reference to the id column in foreign table with onDelete, onUpdate, and fkName options. onDelete and onUpdate options describe the behavior for how links between tables will be checked when deleting or changing corresponding columns' values. Such a relationship will be represented as a FOREIGN KEY constraint on table creation.

fun <T : Comparable<T>> optReference(name: String, refColumn: Column<T>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<T?>
@JvmName(name = "optReferenceByIdColumn")
fun <T : Comparable<T>, E : EntityID<T>> optReference(name: String, refColumn: Column<E>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<E?>

Creates a column with the specified name with an optional reference to the refColumn column with onDelete, onUpdate, and fkName options. onDelete and onUpdate options describe the behavior for how links between tables will be checked when deleting or changing corresponding columns' values. Such a relationship will be represented as a FOREIGN KEY constraint on table creation.

Link copied to clipboard
fun <T : Comparable<T>> reference(name: String, foreign: IdTable<T>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<EntityID<T>>

Creates a column with the specified name with a reference to the id column in foreign table and with onDelete, onUpdate, and fkName options. onDelete and onUpdate options describe the behavior for how links between tables will be checked when deleting or changing corresponding columns' values. Such a relationship will be represented as a FOREIGN KEY constraint on table creation.

fun <T : Comparable<T>> reference(name: String, refColumn: Column<T>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<T>
@JvmName(name = "referenceByIdColumn")
fun <T : Comparable<T>, E : EntityID<T>> reference(name: String, refColumn: Column<E>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): Column<E>

Creates a column with the specified name with a reference to the refColumn column and with onDelete, onUpdate, and fkName options. onDelete and onUpdate options describe the behavior for how links between tables will be checked when deleting or changing corresponding columns' values. Such a relationship will be represented as a FOREIGN KEY constraint on table creation.

Link copied to clipboard
infix fun <T : Comparable<T>, S : T, C : Column<S>> C.references(ref: Column<T>): C

Creates a reference from this @receiver column to a ref column.

fun <T : Comparable<T>, S : T, C : Column<S>> C.references(ref: Column<T>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): C
@JvmName(name = "referencesById")
fun <T : Comparable<T>, S : T, C : Column<S>> C.references(ref: Column<EntityID<T>>, onDelete: ReferenceOption? = null, onUpdate: ReferenceOption? = null, fkName: String? = null): C

Creates a reference from this @receiver column to a ref column with onDelete, onUpdate, and fkName options. onDelete and onUpdate options describe the behavior for how links between tables will be checked when deleting or changing corresponding columns' values. Such a relationship will be represented as a FOREIGN KEY constraint on table creation.

Link copied to clipboard
fun <T> registerColumn(name: String, type: IColumnType<T & Any>): Column<T>

Adds a column of the specified type and with the specified name to the table.

Link copied to clipboard

Adds all wrapped column components of a CompositeColumn to the table.

Link copied to clipboard
fun <TColumn : Column<*>> replaceColumn(oldColumn: Column<*>, newColumn: TColumn): TColumn

Replaces the specified oldColumn with the specified newColumn in the table. Mostly used internally by the library.

Link copied to clipboard
open infix override fun rightJoin(otherTable: ColumnSet): Join

Creates a right outer join relation with otherTable.

Link copied to clipboard
fun select(columns: List<Expression<*>>): Query

Creates a SELECT Query using a list of columns or expressions from this ColumnSet.

fun select(column: Expression<*>, vararg columns: Expression<*>): Query

Creates a SELECT Query by selecting either a single column, or a subset of columns, from this ColumnSet.

Link copied to clipboard
Link copied to clipboard

Creates a SELECT Query by selecting all columns from this ColumnSet.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun short(name: String): Column<Short>

Creates a numeric column, with the specified name, for storing 2-byte integers.

Link copied to clipboard
fun slice(columns: List<Expression<*>>): FieldSet
fun slice(column: Expression<*>, vararg columns: Expression<*>): FieldSet
Link copied to clipboard

Returns the list of tables to which the columns in this column set belong.

Link copied to clipboard
fun text(name: String, collate: String? = null, eagerLoading: Boolean = false): Column<String>

Creates a character column, with the specified name, for storing strings of arbitrary length using the specified collate type. If no collated type is specified, then the database default is used.

Link copied to clipboard
@JvmName(name = "transformNullable")
fun <Unwrapped : Any, Wrapped : Any> Column<Unwrapped?>.transform(transformer: ColumnTransformer<Unwrapped?, Wrapped?>): Column<Wrapped?>

Transforms a nullable column by specifying a transformer.

Transforms a column by specifying a transformer.

@JvmName(name = "transformNullable")
fun <Unwrapped : Any, Wrapped : Any> Column<Unwrapped?>.transform(wrap: (Unwrapped?) -> Wrapped?, unwrap: (Wrapped?) -> Unwrapped?): Column<Wrapped?>

Transforms a nullable column by specifying transformation functions.

Transforms a column by specifying transformation functions.

Link copied to clipboard
fun ubyte(name: String): Column<UByte>

Creates a numeric column, with the specified name, for storing 1-byte unsigned integers.

Link copied to clipboard
fun uinteger(name: String): Column<UInt>

Creates a numeric column, with the specified name, for storing 4-byte unsigned integers.

Link copied to clipboard
fun ulong(name: String): Column<ULong>

Creates a numeric column, with the specified name, for storing 8-byte unsigned integers.

Link copied to clipboard
fun <T> Column<T>.uniqueIndex(customIndexName: String? = null): Column<T>

Creates a unique index composed by this column only.

fun uniqueIndex(vararg columns: Column<*>, filterCondition: FilterCondition = null)
fun uniqueIndex(customIndexName: String? = null, vararg columns: Column<*>, functions: List<ExpressionWithColumnType<*>>? = null, filterCondition: FilterCondition = null)

Creates a unique index.

Link copied to clipboard
fun ushort(name: String): Column<UShort>

Creates a numeric column, with the specified name, for storing 2-byte unsigned integers.

Link copied to clipboard
fun uuid(name: String): Column<UUID>

Creates a binary column, with the specified name, for storing UUIDs.

Link copied to clipboard
fun varchar(name: String, length: Int, collate: String? = null): Column<String>

Creates a character column, with the specified name, for storing strings with the specified maximum length using the specified text collate type. If no collate type is specified then the database default is used.

Link copied to clipboard
fun <T> Column<T>.withDefinition(vararg definition: Any): Column<T>

Appends a database-specific column definition to this column's SQL in a CREATE TABLE statement.