diff --git a/orm_lib/inc/drogon/orm/SqlBinder.h b/orm_lib/inc/drogon/orm/SqlBinder.h index 03365c04..3ba1aa6f 100644 --- a/orm_lib/inc/drogon/orm/SqlBinder.h +++ b/orm_lib/inc/drogon/orm/SqlBinder.h @@ -176,8 +176,8 @@ class CallbackHolder : public CallbackHolderBase run(result); } - CallbackHolder(Function &&function) - : function_(std::forward(function)) + template + CallbackHolder(T &&function) : function_(std::forward(function)) { static_assert(traits::isSqlCallback, "Your sql callback function type is wrong!"); @@ -323,7 +323,8 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable SqlBinder &operator=(SqlBinder &&that) = delete; ~SqlBinder(); template > + typename traits = + FunctionTraits::type>> typename std::enable_if::type & operator>>(CallbackType &&callback) @@ -335,7 +336,8 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable } template > + typename traits = + FunctionTraits::type>> typename std::enable_if::type & operator>>(CallbackType &&callback) @@ -346,12 +348,13 @@ class DROGON_EXPORT SqlBinder : public trantor::NonCopyable } template > + typename traits = + FunctionTraits::type>> typename std::enable_if::type &operator>>( CallbackType &&callback) { callbackHolder_ = std::shared_ptr( - new CallbackHolder( + new CallbackHolder::type>( std::forward(callback))); return *this; } diff --git a/orm_lib/tests/db_test.cc b/orm_lib/tests/db_test.cc index de3bf28d..86ec7183 100644 --- a/orm_lib/tests/db_test.cc +++ b/orm_lib/tests/db_test.cc @@ -32,6 +32,9 @@ using namespace std::chrono_literals; using namespace drogon::orm; +void expFunction(const DrogonDbException &e) +{ +} #if USE_POSTGRESQL DbClientPtr postgreClient; DROGON_TEST(PostgreTest) @@ -40,6 +43,12 @@ DROGON_TEST(PostgreTest) // Prepare the test environment *clientPtr << "DROP TABLE IF EXISTS USERS" >> [TEST_CTX](const Result &r) { SUCCESS(); + clientPtr->execSqlAsync( + "select 1 as result", + [TEST_CTX](const drogon::orm::Result &r) { + MANDATE(r.size() == 1); + }, + expFunction); } >> [TEST_CTX](const DrogonDbException &e) { FAULT("postgresql - Prepare the test environment(0) what():" + std::string(e.base().what())); @@ -674,6 +683,7 @@ DROGON_TEST(PostgreTest) } }; drogon::sync_wait(coro_test()); + #endif } #endif @@ -686,7 +696,15 @@ DROGON_TEST(MySQLTest) REQUIRE(clientPtr != nullptr); // Prepare the test environment *clientPtr << "CREATE DATABASE IF NOT EXISTS drogonTestMysql" >> - [TEST_CTX](const Result &r) { SUCCESS(); } >> + [TEST_CTX](const Result &r) { + SUCCESS(); + clientPtr->execSqlAsync( + "select 1 as result", + [TEST_CTX](const drogon::orm::Result &r) { + MANDATE(r.size() == 1); + }, + expFunction); + } >> [TEST_CTX](const DrogonDbException &e) { FAULT("mysql - Prepare the test environment(0) what():" + std::string(e.base().what())); @@ -1260,6 +1278,7 @@ DROGON_TEST(MySQLTest) } }; drogon::sync_wait(coro_test()); + #endif } #endif @@ -1274,6 +1293,12 @@ DROGON_TEST(SQLite3Test) // Prepare the test environment *clientPtr << "DROP TABLE IF EXISTS users" >> [TEST_CTX](const Result &r) { SUCCESS(); + clientPtr->execSqlAsync( + "select 1 as result", + [TEST_CTX](const drogon::orm::Result &r) { + MANDATE(r.size() == 1); + }, + expFunction); } >> [TEST_CTX](const DrogonDbException &e) { FAULT("sqlite3 - Prepare the test environment(0): what():" + std::string(e.base().what())); @@ -1906,6 +1931,7 @@ DROGON_TEST(SQLite3Test) trantor::EventLoop::getEventLoopOfCurrentThread(), 1.0s); }; drogon::sync_wait(coro_test()); + #endif } #endif