|
| | Mapper (DbClientPtr client) |
| | Construct a new Mapper object.
|
| Mapper< T > & | limit (size_t limit) |
| | Add a limit to the query.
|
| Mapper< T > & | offset (size_t offset) |
| | Add a offset to the query.
|
| Mapper< T > & | orderBy (const std::string &colName, const SortOrder &order=SortOrder::ASC) |
| | Set the order of the results.
|
| Mapper< T > & | orderBy (size_t colIndex, const SortOrder &order=SortOrder::ASC) |
| | Set the order of the results.
|
| Mapper< T > & | paginate (size_t page, size_t perPage) |
| | Set limit and offset to achieve pagination. This method will override limit() and offset(), and will be overridden by them.
|
| Mapper< T > & | forUpdate () |
| | Lock the result for updating.
|
| Mapper< T > & | innerJoin (const std::string &table, const std::string &onLeft, const std::string &onRight) |
| | Add an INNER JOIN clause to the query.
|
| Mapper< T > & | leftJoin (const std::string &table, const std::string &onLeft, const std::string &onRight) |
| | Add a LEFT JOIN clause to the query.
|
| Mapper< T > & | rightJoin (const std::string &table, const std::string &onLeft, const std::string &onRight) |
| | Add a RIGHT JOIN clause to the query.
|
| template<typename U = T> |
| T | findByPrimaryKey (const TraitsPKType &key) noexcept(false) |
| | Find a record by the primary key.
|
| template<typename U = T> |
| void | findByPrimaryKey (const TraitsPKType &key, const SingleRowCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously find a record by the primary key.
|
| template<typename U = T> |
| std::future< T > | findFutureByPrimaryKey (const TraitsPKType &key) noexcept |
| | Asynchronously find a record by the primary key.
|
| std::vector< T > | findAll () noexcept(false) |
| | Find all the records in the table.
|
| void | findAll (const MultipleRowsCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously find all the records in the table.
|
| std::future< std::vector< T > > | findFutureAll () noexcept |
| | Asynchronously find all the records in the table.
|
| size_t | count (const Criteria &criteria=Criteria()) noexcept(false) |
| | Get the count of rows that match the given criteria.
|
| void | count (const Criteria &criteria, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously get the number of rows that match the given criteria.
|
| std::future< size_t > | countFuture (const Criteria &criteria=Criteria()) noexcept |
| | Asynchronously get the number of rows that match the given criteria.
|
| T | findOne (const Criteria &criteria) noexcept(false) |
| | Find one record that matches the given criteria.
|
| void | findOne (const Criteria &criteria, const SingleRowCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously find one record that matches the given criteria.
|
| std::future< T > | findFutureOne (const Criteria &criteria) noexcept |
| | Asynchronously find one record that matches the given criteria.
|
| std::vector< T > | findBy (const Criteria &criteria) noexcept(false) |
| | Select the rows that match the given criteria.
|
| void | findBy (const Criteria &criteria, const MultipleRowsCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously select the rows that match the given criteria.
|
| std::future< std::vector< T > > | findFutureBy (const Criteria &criteria) noexcept |
| | Asynchronously select the rows that match the given criteria.
|
| void | insert (T &obj) noexcept(false) |
| | Insert a row into the table.
|
| void | insert (const T &obj, const SingleRowCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously insert a row into the table.
|
| std::future< T > | insertFuture (const T &) noexcept |
| | Asynchronously insert a row into the table.
|
| size_t | update (const T &obj) noexcept(false) |
| | Update a record.
|
| void | update (const T &obj, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously update a record.
|
| std::future< size_t > | updateFuture (const T &obj) noexcept |
| | Asynchronously update a record.
|
| template<typename... Arguments> |
| size_t | updateBy (const std::vector< std::string > &colNames, const Criteria &criteria, Arguments &&...args) noexcept(false) |
| | Update a record that match both the primary key and the given criteria.
|
| template<typename... Arguments> |
| void | updateBy (const std::vector< std::string > &colNames, const CountCallback &rcb, const ExceptionCallback &ecb, const Criteria &criteria, Arguments &&...args) noexcept |
| | Asynchronously select the rows that match both the primary key and the given criteria.
|
| template<typename... Arguments> |
| std::future< size_t > | updateFutureBy (const std::vector< std::string > &colNames, const Criteria &criteria, Arguments &&...args) noexcept |
| | Asynchronously update a record that match both the primary key and the given criteria.
|
| template<typename... Arguments> |
| size_t | increment (const std::vector< std::string > &colNames, const Criteria &criteria, Arguments... args) noexcept(false) |
| | Update some records that match the given criteria.
|
| template<typename... Arguments> |
| void | increment (const std::vector< std::string > &colNames, const CountCallback &rcb, const ExceptionCallback &ecb, const Criteria &criteria, Arguments... args) noexcept |
| | Asynchronously update some records that match the given criteria.
|
| template<typename... Arguments> |
| std::future< size_t > | incrementFuture (const std::vector< std::string > &colNames, const Criteria &criteria, Arguments... args) noexcept |
| | Asynchronously update some records that match the given criteria.
|
| size_t | deleteOne (const T &obj) noexcept(false) |
| | Delete a record from the table.
|
| void | deleteOne (const T &obj, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously delete a record from the table.
|
| std::future< size_t > | deleteFutureOne (const T &obj) noexcept |
| | Asynchronously delete a record from the table.
|
| size_t | deleteBy (const Criteria &criteria) noexcept(false) |
| | Delete records that satisfy the given criteria.
|
| void | deleteBy (const Criteria &criteria, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Delete records that match the given criteria asynchronously.
|
| std::future< size_t > | deleteFutureBy (const Criteria &criteria) noexcept |
| | Delete records that match the given criteria asynchronously.
|
| size_t | deleteByPrimaryKey (const TraitsPKType &key) noexcept(false) |
| | Delete the record that matches the given primary key.
|
| void | deleteByPrimaryKey (const TraitsPKType &key, const CountCallback &rcb, const ExceptionCallback &ecb) noexcept |
| | Asynchronously delete the record that matches the given primary key.
|
| std::future< size_t > | deleteFutureByPrimaryKey (const TraitsPKType &key) noexcept |
| | Delete the record that matches the given primary key asynchronously.
|
template<typename T>
class drogon::orm::Mapper< T >
The mapper template.
- Template Parameters
-
| T | The type of the model to be mapped. |
The mapping between the model object and the database table is performed by the Mapper class template. The Mapper class template encapsulates common operations such as adding, deleting, and changing, so that the user can perform the above operations without writing a SQL statement.
The construction of the Mapper object is very simple. The template parameter is the type of the model you want to access. The constructor has only one parameter, which is the DbClient smart pointer mentioned earlier. As mentioned earlier, the Transaction class is a subclass of DbClient, so you can also construct a Mapper object with a smart pointer to a transaction, which means that the Mapper mapping also supports transactions.
Like DbClient, Mapper also provides asynchronous and synchronous interfaces. The synchronous interface is blocked and may throw an exception. The returned future object is blocked in the get() method and may throw an exception. The normal asynchronous interface does not throw an exception, but returns the result through two callbacks (result callback and exception callback). The type of the exception callback is the same as that in the DbClient interface. The result callback is also divided into several categories according to the interface function.