Entity

open class Entity<ID : Any>(val id: EntityID<ID>)

A row of EntityClass.table, with the columns it should expose declared as delegated properties.

Subclass one of the typed variants — IntEntity, LongEntity, UuidEntity, CompositeEntity — and give the class a companion object of the matching EntityClass:

class Film(id: EntityID<Int>) : IntEntity(id) {
var title by Films.title
val director by Director referencedOn Films.director

companion object : IntEntityClass<Film>(Films)
}

Reading and writing a column property does not suspend and issues no statement: a write is staged in the current transaction's EntityCache and reaches the database on the next flush. The operations that do use the connection — flush, refresh, delete, and the relationship accessors — are suspending.

Parameters

id

The unique stored identity value for the mapped record.

Inheritors

Constructors

Link copied to clipboard
constructor(id: EntityID<ID>)

Properties

Link copied to clipboard

This entity's committed column values. Values a transaction has staged but not committed are held by that transaction's EntityCache instead.

Link copied to clipboard

The R2dbcDatabase associated with the record mapped to this Entity instance.

Link copied to clipboard
val id: EntityID<ID>
Link copied to clipboard

The associated EntityClass that manages this Entity instance.

Link copied to clipboard

The final column-value mapping for this Entity instance after being flushed and retrieved from the database.

Functions

Link copied to clipboard
open suspend fun delete()

Deletes this Entity instance, both from the cache and from the database.

Link copied to clipboard
open suspend fun flush(batch: EntityBatchUpdate? = null): Boolean

Sends all cached inserts and updates for this Entity instance to the database.

Link copied to clipboard
operator fun <T> Column<T>.getValue(o: Entity<ID>, desc: KProperty<*>): T

operator fun <T> CompositeColumn<T>.getValue(o: Entity<ID>, desc: KProperty<*>): T

Reads a property delegated to a CompositeColumn, which stores a single value across several columns:

Reads a property delegated to a transformed column, converting the stored value on the way out:

Link copied to clipboard
fun <T> Column<T>.lookup(): T

Returns the value assigned to this column mapping.

Link copied to clipboard
open suspend fun refresh(flush: Boolean = false)

Updates the fields of this Entity instance with values retrieved from the database. Override this function to refresh some additional state, if any.

Link copied to clipboard
operator fun <T> Column<T>.setValue(entity: Entity<ID>, desc: KProperty<*>, value: T)

operator fun <T> CompositeColumn<T>.setValue(o: Entity<ID>, desc: KProperty<*>, value: T)

Writes a property delegated to a CompositeColumn, staging one value per underlying column.

Writes a property delegated to a transformed column, converting the value back to what the column stores.

Link copied to clipboard

Declares a many-to-many relationship held by the intermediate table, whose references to this entity's table and to the target's table are inferred from its foreign keys:

fun <TID : Any, Target : Entity<TID>> EntityClass<TID, Target>.via(sourceColumn: Column<EntityID<ID>>, targetColumn: Column<EntityID<TID>>): InnerTableLink<ID, Entity<ID>, TID, Target>

Declares a many-to-many relationship, naming sourceColumn and targetColumn explicitly. Use this overload when the intermediate table holds more than one reference to either side, which leaves nothing to infer: