newSuspend

open suspend fun newSuspend(init: suspend T.() -> Unit): T

Creates a new Entity instance with the fields set in the init block, schedules its insert, flushes the entity cache, and returns the fully-hydrated entity with its auto-generated id and database-generated columns populated.

This is the counterpart of the JDBC DAO's EntityClass.new: after this call the entity's Entity.id is immediately usable. The non-suspending new of this class schedules the insert without flushing, and so leaves the id unresolved — JDBC code that reads the id right after creating an entity should be migrated to this function, not to new.

Because this function suspends, so does init: other DAO operations can be called from inside the block.

Return

The created and flushed entity.

Parameters

init

Suspending block where the entity's fields can be set.


open suspend fun newSuspend(id: ID?, init: suspend T.() -> Unit): T

Composite/explicit-id variant of newSuspend: creates a new Entity instance with the fields set in the init block and with the provided id, schedules its insert, flushes the entity cache, and returns the fully-hydrated entity.

Return

The created and flushed entity.

Parameters

id

The id of the entity. Set this to null if it should be automatically generated.

init

Suspending block where the entity's fields can be set.