mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 03:38:03 +08:00
Support CoroMapper method chaining (#1103)
This commit is contained in:
parent
1c44cf7e4c
commit
e9fafc643d
@ -119,6 +119,74 @@ class CoroMapper : public Mapper<T>
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
// Query condition overrides
|
||||
|
||||
/**
|
||||
* @brief Add a limit to the query.
|
||||
*
|
||||
* @param limit The limit
|
||||
* @return CoroMapper<T>& The CoroMapper itself.
|
||||
*/
|
||||
CoroMapper<T> &limit(size_t limit)
|
||||
{
|
||||
Mapper<T>::limit(limit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add a offset to the query.
|
||||
*
|
||||
* @param offset The offset.
|
||||
* @return CoroMapper<T>& The CoroMapper itself.
|
||||
*/
|
||||
CoroMapper<T> &offset(size_t offset)
|
||||
{
|
||||
Mapper<T>::offset(offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the order of the results.
|
||||
*
|
||||
* @param colName the column name, the results are sorted by that column
|
||||
* @param order Ascending or descending order
|
||||
* @return CoroMapper<T>& The CoroMapper itself.
|
||||
*/
|
||||
CoroMapper<T> &orderBy(const std::string &colName,
|
||||
const SortOrder &order = SortOrder::ASC)
|
||||
{
|
||||
Mapper<T>::orderBy(colName, order);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the order of the results.
|
||||
*
|
||||
* @param colIndex the column index, the results are sorted by that column
|
||||
* @param order Ascending or descending order
|
||||
* @return CoroMapper<T>& The CoroMapper itself.
|
||||
*/
|
||||
CoroMapper<T> &orderBy(size_t colIndex,
|
||||
const SortOrder &order = SortOrder::ASC)
|
||||
{
|
||||
Mapper<T>::orderBy(colIndex, order);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lock the result for updating.
|
||||
*
|
||||
* @return CoroMapper<T>& The CoroMapper itself.
|
||||
*/
|
||||
CoroMapper<T> &forUpdate()
|
||||
{
|
||||
Mapper<T>::forUpdate();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Read api for coroutines
|
||||
|
||||
inline internal::MapperAwaiter<std::vector<T>> findAll()
|
||||
{
|
||||
return findBy(Criteria());
|
||||
|
@ -666,6 +666,20 @@ DROGON_TEST(PostgreTest)
|
||||
{
|
||||
SUCCESS();
|
||||
}
|
||||
try
|
||||
{
|
||||
CoroMapper<Users> mapper(clientPtr);
|
||||
auto users = co_await mapper.orderBy(Users::Cols::_user_id)
|
||||
.limit(2)
|
||||
.findAll();
|
||||
MANDATE(users.size() == 2);
|
||||
SUCCESS();
|
||||
}
|
||||
catch (const DrogonDbException &e)
|
||||
{
|
||||
FAULT("postgresql - ORM mapper coroutine interface(2) what():" +
|
||||
std::string(e.base().what()));
|
||||
}
|
||||
/// 7.4 Transactions
|
||||
try
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user