English | 简体中文

api-docs / org.ktorm.entity / add

add

fun <E : Entity<E>, T : Table<E>> EntitySequence<E, T>.add(
    entity: E
): Int
(source code)

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

Entity.flushChanges

Entity.delete

Since
2.7