Fix a bug in the Mapper::insertFuture() (#620)

This commit is contained in:
An Tao 2020-10-29 20:09:16 +08:00 committed by GitHub
parent dbf21f7dbc
commit 594911b7a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View File

@ -1243,8 +1243,15 @@ inline std::future<T> Mapper<T>::insertFuture(const T &obj) noexcept
tmp.findByPrimaryKey(
newObj.getPrimaryKey(),
[prom](T selObj) { prom->set_value(selObj); },
[prom](const std::exception_ptr &e) {
prom->set_exception(e);
[prom](const DrogonDbException &e) {
try
{
throw e;
}
catch (...)
{
prom->set_exception(std::current_exception());
}
});
}
else

View File

@ -31,7 +31,7 @@ using namespace drogon::orm;
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
constexpr int postgre_tests = 43;
constexpr int postgre_tests = 44;
constexpr int mysql_tests = 45;
constexpr int sqlite_tests = 47;
@ -650,13 +650,30 @@ void doPostgreTest(const drogon::orm::DbClientPtr &clientPtr)
testOutput(false,
"postgresql - ORM mapper asynchronous interface(0)");
});
/// 6.1.5 insert future
user.setUserId("pg_future");
auto fu = mapper.insertFuture(user);
try
{
auto u = fu.get();
testOutput(true,
"postgresql - ORM mapper asynchronous future interface(0)");
}
catch (const DrogonDbException &e)
{
std::cerr << e.base().what() << std::endl;
testOutput(false,
"postgresql - ORM mapper asynchronous future interface(0)");
}
/// 6.2 insert
user.setUserId("pg1");
user.setUserName("postgres1");
mapper.insert(
user,
[](Users ret) {
testOutput(ret.getPrimaryKey() == 2,
testOutput(ret.getPrimaryKey() == 3,
"postgresql - ORM mapper asynchronous interface(1)");
},
[](const DrogonDbException &e) {