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

◆ MakeSelecter() [1/2]

template<EntityValueType ENTITY>
constexpr auto sqt::DataContext< ENTITY >::MakeSelecter ( )
staticconstexprnoexcept

Creates a selecter for retrieving entities from the database table.

Returns
A new selecter instance, whose result element type is the entity type.

The returned selecter corresponds to a SELECT SQL statement without any conditions, so it will select all entities from the table. To apply select conditions, use the Where(), OrderBy(), and Limit() methods of the selecter to create a new selecter with conditions. The following code demonstrates how to use the selecter:

// The entity type, assuming its table type has been defined and registered, and its
// columns' names are defined as the same as the entity's field names.
struct MyEntity {
int id{};
std::string name;
};
// Create the selecter with a condition.
sqt::Table<MyEntity>.name != "Unknown"
);
// Create a data context, assuming the shared_db is an opened database instance.
sqt::DataContext<MyEntity> data_context{ shared_db };
// Prepare the selecter to create a corresponding executor.
auto executor = data_context.Prepare(selecter);
// Execute the statement to obtain the result.
auto result = executor.Execute();
// Iterate through the result and print the entities.
for (const MyEntity& entity : result) {
std::cout << "ID: " << entity.id << ", Name: " << entity.name << '\n';
}
static constexpr auto MakeSelecter() noexcept
Creates a selecter for retrieving entities from the database table.
Definition data_context.h:520
Executor< QUERIER > Prepare(const QUERIER &querier)
Creates an executor for executing the specified querier.
Definition data_context.h:639
Provides a set of operations for performing CRUD (Create, Read, Update, Delete) operations on a datab...
Definition data_context.h:96
constexpr const auto & Table
A helper template to retrieve the singleton instance of the table type associated with an entity type...
Definition table_mapping.h:64

The returned selecter selects all columns of the table. To control which columns to select, use the MakeSelecter(const COLUMN&&...) method instead.

For easier-to-use methods, use the following methods from the easy style interface:

  • Select() for selecting a single entity by the specified primary key value.
  • SelectAll() for selecting all entities in the table.
See also
sqt::DataContext<>::MakeSelecter(const COLUMNS&... columns);
sqt::DataContext<>::Select()
sqt::DataContext<>::SelectAll()