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:
parent
8faada3aee
commit
d1fbab9e47
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <sqlpp11/connection.h>
|
#include <sqlpp11/connection.h>
|
||||||
#include <sqlpp11/connection_pool.h>
|
#include <sqlpp11/connection_pool.h>
|
||||||
|
#include <sqlpp11/type_traits.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
@ -88,6 +89,30 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
return _impl->prepare(t);
|
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.");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user