From d1fbab9e475dd0ecf72ba9d3bdd07c1d61fa8b5a Mon Sep 17 00:00:00 2001 From: Frank Park Date: Wed, 12 Apr 2017 01:26:11 -0400 Subject: [PATCH] enable direct query through pool_connection with limited functionality --- include/sqlpp11/pool_connection.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/sqlpp11/pool_connection.h b/include/sqlpp11/pool_connection.h index cc9bfe09..436a5d5d 100644 --- a/include/sqlpp11/pool_connection.h +++ b/include/sqlpp11/pool_connection.h @@ -29,6 +29,7 @@ #include #include +#include #include namespace sqlpp @@ -88,6 +89,30 @@ namespace sqlpp { return _impl->prepare(t); } + + template::value || + is_invocable::value || + is_invocable::value && + !is_invocable::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::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."); + } }; }