0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 12:51:13 +08:00

enable direct query through pool_connection with limited functionality

This commit is contained in:
Frank Park 2017-04-12 01:26:11 -04:00
parent 8faada3aee
commit d1fbab9e47

View File

@ -29,6 +29,7 @@
#include <sqlpp11/connection.h>
#include <sqlpp11/connection_pool.h>
#include <sqlpp11/type_traits.h>
#include <memory>
namespace sqlpp
@ -88,6 +89,30 @@ namespace sqlpp
{
return _impl->prepare(t);
}
template<typename Query, typename Lambda,
typename std::enable_if<is_invocable<Lambda>::value ||
is_invocable<Lambda, sqlpp::exception>::value ||
is_invocable<Lambda, sqlpp::exception, decltype(pool_connection()(Query()))>::value &&
!is_invocable<Lambda, sqlpp::exception, decltype(pool_connection()(Query())), pool_connection>::value, int>::type = 0>
void operator()(Query query, Lambda callback)
{
try
{
invoke_callback(sqlpp::exception(sqlpp::exception::ok), pool_connection(), std::move(operator()(query)), callback);
}
catch (const std::exception& e)
{
invoke_callback(sqlpp::exception(sqlpp::exception::query_error, e.what()), pool_connection(), decltype(pool_connection()(Query()))(), callback);
}
}
template<typename Query, typename Lambda,
typename std::enable_if<is_invocable<Lambda, sqlpp::exception, decltype(pool_connection()(Query())), pool_connection>::value, int>::type = 0>
void operator()(Query query, Lambda callback)
{
static_assert(false, "Direct query with pool connection forbids callback with parameter of type connection.");
}
};
}