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

◆ Select()

template<EntityValueType ENTITY>
template<typename E = ENTITY>
requires PrimaryKeyEntityValueType<E>
std::optional< E > sqt::DataContext< ENTITY >::Select ( const typename TableType< E >::PrimaryKeyType::ValueType & primary_key)

Retrieves a single entity by the specified primary key value from the database table.

Parameters
primary_keyThe primary key value of the entity to be retrieved.
Returns
The entity if found; otherwise, std::nullopt if the entity with the specified primary key value does not exist.
Exceptions
sqt::SQLErrorThrown if the selection fails.
Note
This method is only available if the entity type has a primary key. Use the SQT_PRIMARY_KEY or SQT_PRIMARY_KEY_AUTO_INC macro to define a primary key.

For more control over which entities to retrieve, use the MakeSelecter() method from the complex style interface to create a selecter and apply custom conditions. Furthermore, use the MakeSelecter(const COLUMNS&...) method to specify which columns of the entity to select.

See also
sqt::DataContext<>::MakeSelecter()
sqt::DataContext<>::MakeSelecter(const COLUMNS&... columns)
sqt::DataContext<>::SelectAll()
SQT_PRIMARY_KEY
SQT_PRIMARY_KEY_AUTO_INC