addEntity

fun <E : Entity<E>> Table<E>.addEntity(entity: E): Int(source)

Deprecated

ktorm-global will be removed in the future, please migrate to the standard API.

Insert the given entity into this sequence and return the affected record number.

If we use an auto-increment key in our table, we need to tell Ktorm which is the primary key by calling Table.primaryKey while registering columns, then this function will obtain the generated key from the database and fill it into the corresponding property after the insertion completes. But this requires us not to set the primary key’s value beforehand, otherwise, if you do that, the given value will be inserted into the database, and no keys generated.

Note that after calling this function, the entity will be ATTACHED to the current database.

See also