SQT
A C++ ORM framework for SQLite
Loading...
Searching...
No Matches

◆ Insert()

template<EntityValueType ENTITY>
std::int64_t sqt::DataContext< ENTITY >::Insert ( const ENTITY & entity)

Inserts the specified entity into the database table.

Parameters
entityThe entity to be inserted.
Returns
The generated row ID of the inserted entity.
Exceptions
sqt::SQLErrorThrown if the insertion fails.

This method inserts the entire entity into the database table, including the primary key. However, the primary key value is not automatically generated even if it is auto-incremented. To automatically generate the primary key value, use AutoIncInsert() instead.

If a unique constraint violation occurs, the insertion will fail and throw an exception. To avoid this, use Replace() or AutoIncReplace() to replace the existing row.

For more control over the conflict action and the inserted columns, use the more flexible MakeInserter() and MakeInserter(ASSIGNMENT&&...) methods from the complex style interface.

See also
sqt::DataContext<>::AutoIncInsert()
sqt::DataContext<>::AutoIncReplace()
sqt::DataContext<>::MakeInserter()
sqt::DataContext<>::MakeInserter(ASSIGNMENT&&... assignments)
sqt::DataContext<>::Replace()