File Information
Library: ActiveRecord
Package: ActiveRecord
Header: Poco/ActiveRecord/Query.h
Description
A Query is used to retrieve ActiveRecord objects from a table.
As the name implies, Query supports selection of database rows based on a WHERE clause (see where()).
Furthermore, results can be sorted (see orderBy()) and filtered based on a lambda expression (see filter()).
Optional result paging is controlled by offset() and limit(). The total number of results is available via totalResults().
Member Summary
Member Functions: bind, execute, filter, fixPlaceholders, limit, offset, operator =, orderBy, reset, select, totalResults, where
Constructors
Query
Query() = delete;
Query
explicit Query(
Context::Ptr pContext
);
Query
Query(
const Query & param84
) = delete;
Destructor
~Query
~Query() = default;
Member Functions
bind
template < typename T > Query & bind(
const T & value
);
Bind a value to a placeholder in the where() clause.
For each placeholder (?) in the where() clause, a value must be bound with bind() before the query can be executed.
execute
std::vector < typename ActRec::Ptr > execute();
Execute the query and return a vector with the results.
filter
Query & filter(
const std::function < bool (const ActRec &)> & fn
);
Specify a lambda expression for filtering results.
The lamda takes a const reference to the ActiveRecord (template argument) as parameter and must return a bool. If the lambda returns true, the respective ActiveRecord is included in the query result.
filter
Query & filter(
std::function < bool (const ActRec &)> && fn
);
limit
Query & limit(
std::size_t limit
);
Specify the maximum number of rows to return for paging.
offset
Query & offset(
std::size_t offset
);
Specify the index or offset of the first row to return for paging.
operator =
Query & operator = (
const Query & param85
) = delete;
orderBy
Query & orderBy(
const std::string & order
);
Specify a column name and optional direction (ASC, DESC) to order the result by.
reset
void reset();
Resets the query so that it can be executed again, with potentially different parameters.
totalResults
std::size_t totalResults() const;
In case of a paged query, returns the total number of results that would be returned without paging.
where
Query & where(
const std::string & clause
);
Specify a WHERE clause (without the WHERE keyword) to select only rows matching the clause.
Placeholders (?) can be used in the clause. For each placeholder, an actual value must be bound before the query is executed (see bind()).
fixPlaceholders
std::string fixPlaceholders(
const std::string & clause
);
select
void select();