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

◆ MakeSelecter() [2/2]

template<EntityValueType ENTITY>
template<ColumnType... COLUMNS>
constexpr auto sqt::DataContext< ENTITY >::MakeSelecter ( const COLUMNS &... columns)
staticconstexprnoexcept

Creates a selecter for retrieving the specified columns from the database table.

Template Parameters
COLUMNSA pack of the column types.
Parameters
columnsThe columns to be retrieved.
Returns
A new selecter instance, whose result element type is a composite value type (a std::tuple<> of the specified columns' value types).

This method is similar to the MakeSelecter() method, with the following differences:

  • The returned selecter selects only the specified columns of the table, rather than all columns.
  • The result element type is a composite value type rather than the entity type.

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 two columns.
);
// 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 tuples.
for (const std::tuple<int, std::string>& tuple : result) {
std::cout << "ID: " << std::get<0>(tuple) << ", Name: " << std::get<1>(tuple) << '\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
See also
sqt::DataContext<>::MakeSelecter()
sqt::DataContext<>::Select()
sqt::DataContext<>::SelectAll()