0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 21:04:15 +08:00

replace query_task with bind, rename helper functions, clean up implementation

This commit is contained in:
Frank Park 2017-04-12 01:00:24 -04:00
parent 510f1f83c4
commit 8faada3aee
2 changed files with 21 additions and 25 deletions

View File

@ -38,7 +38,7 @@
#include <type_traits> #include <type_traits>
#include <sqlpp11/exception.h> #include <sqlpp11/exception.h>
#include <sqlpp11/pool_connection.h> #include <sqlpp11/pool_connection.h>
#include <sqlpp11/query_task.h> #include <sqlpp11/bind.h>
namespace sqlpp namespace sqlpp
{ {
@ -131,7 +131,7 @@ namespace sqlpp
template <typename Connection_config, template <typename Connection_config,
typename Connection_validator = connection_validator::automatic, typename Connection_validator = connection_validator::automatic,
typename Connection = typename std::enable_if<std::is_class<Connection_config::connection>::value, Connection_config::connection>::type> typename Connection = typename std::enable_if<std::is_class<Connection_config::connection>::value, Connection_config::connection>::type>
class connection_pool class connection_pool_t
{ {
friend pool_connection<Connection_config, Connection_validator, Connection>; friend pool_connection<Connection_config, Connection_validator, Connection>;
@ -164,15 +164,15 @@ namespace sqlpp
} }
public: public:
connection_pool(const std::shared_ptr<Connection_config>& config, size_t pool_size) connection_pool_t(const std::shared_ptr<Connection_config>& config, size_t pool_size)
: config(config), maximum_pool_size(pool_size), connection_validator(Connection_validator()) {} : config(config), maximum_pool_size(pool_size), connection_validator(Connection_validator()) {}
~connection_pool() = default; ~connection_pool_t() = default;
connection_pool(const connection_pool&) = delete; connection_pool_t(const connection_pool_t&) = delete;
connection_pool(connection_pool&& other) connection_pool_t(connection_pool_t&& other)
: config(std::move(other.config)), maximum_pool_size(std::move(other.maximum_pool_size)), : config(std::move(other.config)), maximum_pool_size(std::move(other.maximum_pool_size)),
connection_validator(std::move(other.connection_validator)) {} connection_validator(std::move(other.connection_validator)) {}
connection_pool& operator=(const connection_pool&) = delete; connection_pool_t& operator=(const connection_pool_t&) = delete;
connection_pool& operator=(connection_pool&&) = delete; connection_pool_t& operator=(connection_pool_t&&) = delete;
auto get_connection() auto get_connection()
-> pool_connection<Connection_config, Connection_validator, Connection> -> pool_connection<Connection_config, Connection_validator, Connection>
@ -214,7 +214,7 @@ namespace sqlpp
template<typename Query, typename Lambda> template<typename Query, typename Lambda>
void operator()(Query query, Lambda callback) void operator()(Query query, Lambda callback)
{ {
query_task<connection_pool, Query, Lambda>(*this, query, callback)(); sqlpp::bind(*this, query, callback)();
} }
template<typename Query> template<typename Query>
@ -227,10 +227,10 @@ namespace sqlpp
template<typename Connection_config, template<typename Connection_config,
typename Connection_validator = connection_validator::automatic, typename Connection_validator = connection_validator::automatic,
typename Connection = typename std::enable_if<std::is_class<Connection_config::connection>::value, Connection_config::connection>::type> typename Connection = typename std::enable_if<std::is_class<Connection_config::connection>::value, Connection_config::connection>::type>
auto make_connection_pool(const std::shared_ptr<Connection_config>& config, size_t max_pool_size) auto connection_pool(const std::shared_ptr<Connection_config>& config, size_t max_pool_size)
-> connection_pool<Connection_config, Connection_validator, Connection> -> connection_pool_t<Connection_config, Connection_validator, Connection>
{ {
return connection_pool<Connection_config, Connection_validator, Connection>(config, max_pool_size); return connection_pool_t<Connection_config, Connection_validator, Connection>(config, max_pool_size);
} }
} }

View File

@ -28,12 +28,13 @@
#define SQLPP_POOL_CONNECTION_H #define SQLPP_POOL_CONNECTION_H
#include <sqlpp11/connection.h> #include <sqlpp11/connection.h>
#include <sqlpp11/connection_pool.h>
#include <memory> #include <memory>
namespace sqlpp namespace sqlpp
{ {
template <typename Connection_config, typename Connection_validator, typename Connection, template <typename Connection_config, typename Connection_validator, typename Connection,
typename Connection_pool = connection_pool<Connection_config, Connection_validator, Connection>> typename Connection_pool = connection_pool_t<Connection_config, Connection_validator, Connection>>
struct pool_connection : public sqlpp::connection struct pool_connection : public sqlpp::connection
{ {
private: private:
@ -57,6 +58,13 @@ namespace sqlpp
} }
} }
pool_connection(const pool_connection&) = delete;
pool_connection(pool_connection&& other) : _impl(std::move(other._impl)), origin(other.origin)
{
}
pool_connection& operator=(const pool_connection&) = delete;
pool_connection& operator=(pool_connection&& other) = default;
template<typename... Args> template<typename... Args>
auto operator()(Args&&... args) -> decltype(_impl->args(std::forward<Args>(args)...)) auto operator()(Args&&... args) -> decltype(_impl->args(std::forward<Args>(args)...))
{ {
@ -80,18 +88,6 @@ namespace sqlpp
{ {
return _impl->prepare(t); return _impl->prepare(t);
} }
pool_connection(const pool_connection&) = delete;
pool_connection(pool_connection&& other) : _impl(std::move(other._impl)), origin(other.origin)
{
}
pool_connection& operator=(const pool_connection&) = delete;
pool_connection& operator=(pool_connection&& other)
{
_impl = std::move(other._impl);
origin = other.origin;
return *this;
}
}; };
} }