connection info in connection pool progress
This commit is contained in:
parent
12905e3df3
commit
5490e67ecf
|
|
@ -15,7 +15,7 @@ namespace matador::sql {
|
||||||
class connection_pool;
|
class connection_pool;
|
||||||
|
|
||||||
struct identifiable_connection {
|
struct identifiable_connection {
|
||||||
identifiable_connection(size_t id, connection &&conn);
|
identifiable_connection(size_t id, connection conn);
|
||||||
size_t id{};
|
size_t id{};
|
||||||
connection conn;
|
connection conn;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,8 @@ connection &connection::operator=(const connection &x) {
|
||||||
connection::connection( connection&& x ) noexcept
|
connection::connection( connection&& x ) noexcept
|
||||||
: connection_info_(std::move(x.connection_info_))
|
: connection_info_(std::move(x.connection_info_))
|
||||||
, connection_(std::move(x.connection_))
|
, connection_(std::move(x.connection_))
|
||||||
, logger_(std::move(x.logger_)) {}
|
, logger_(std::move(x.logger_))
|
||||||
|
{}
|
||||||
|
|
||||||
connection & connection::operator=(connection &&x) noexcept {
|
connection & connection::operator=(connection &&x) noexcept {
|
||||||
connection_info_ = std::move(x.connection_info_);
|
connection_info_ = std::move(x.connection_info_);
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
identifiable_connection::identifiable_connection(const size_t id, connection &&conn)
|
identifiable_connection::identifiable_connection(const size_t id, connection conn)
|
||||||
: id(id)
|
: id(id)
|
||||||
, conn(std::move(conn)){}
|
, conn(std::move(conn)){}
|
||||||
|
|
||||||
|
|
@ -58,7 +59,10 @@ connection_pool::connection_pool(const std::string& dns, size_t count)
|
||||||
connection_repo_.reserve(count);
|
connection_repo_.reserve(count);
|
||||||
while (count) {
|
while (count) {
|
||||||
connection c(info_);
|
connection c(info_);
|
||||||
connection_repo_.emplace_back(count, std::move(c));
|
auto&& cc = std::move(c);
|
||||||
|
const auto ic = identifiable_connection{count, std::move(cc)};
|
||||||
|
connection_repo_.push_back(ic);
|
||||||
|
// connection_repo_.emplace_back(count, std::move(cc));
|
||||||
// connection_repo_.emplace_back(count, connection{info_});
|
// connection_repo_.emplace_back(count, connection{info_});
|
||||||
auto &conn = connection_repo_.back();
|
auto &conn = connection_repo_.back();
|
||||||
idle_connections_.emplace(conn.id, &conn);
|
idle_connections_.emplace(conn.id, &conn);
|
||||||
|
|
|
||||||
|
|
@ -459,10 +459,10 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship"
|
||||||
{ 9, 3 }
|
{ 9, 3 }
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const auto &ri: recipe_ingredients) {
|
for (const auto & [recipe_id, ingredient_id]: recipe_ingredients) {
|
||||||
res = query::insert()
|
res = query::insert()
|
||||||
.into("recipe_ingredients", column_generator::generate(repo, "recipe_ingredients", true))
|
.into("recipe_ingredients", column_generator::generate(repo, "recipe_ingredients", true))
|
||||||
.values({ri.first, ri.second})
|
.values({recipe_id, ingredient_id})
|
||||||
.execute(db);
|
.execute(db);
|
||||||
REQUIRE(res.is_ok());
|
REQUIRE(res.is_ok());
|
||||||
REQUIRE(*res == 1);
|
REQUIRE(*res == 1);
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,8 @@ sql::connection_impl *test_backend_service::create(const sql::connection_info &i
|
||||||
return noop_connections_.insert(std::make_unique<test_connection>(info)).first->get();
|
return noop_connections_.insert(std::make_unique<test_connection>(info)).first->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_backend_service::destroy(sql::connection_impl *impl)
|
void test_backend_service::destroy(sql::connection_impl *impl) {
|
||||||
{
|
const auto it = std::find_if(noop_connections_.begin(), noop_connections_.end(), [impl](const auto &item) {
|
||||||
auto it = std::find_if(noop_connections_.begin(), noop_connections_.end(), [impl](const auto &item) {
|
|
||||||
return impl == item.get();
|
return impl == item.get();
|
||||||
});
|
});
|
||||||
if (it != noop_connections_.end()) {
|
if (it != noop_connections_.end()) {
|
||||||
|
|
@ -21,8 +20,7 @@ void test_backend_service::destroy(sql::connection_impl *impl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sql::dialect *test_backend_service::dialect() const
|
const sql::dialect *test_backend_service::dialect() const {
|
||||||
{
|
|
||||||
static sql::dialect dialect_ = sql::dialect_builder::builder()
|
static sql::dialect dialect_ = sql::dialect_builder::builder()
|
||||||
.create()
|
.create()
|
||||||
.build();
|
.build();
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ test_connection::test_connection(const sql::connection_info &info)
|
||||||
|
|
||||||
utils::result<void, utils::error> test_connection::open() {
|
utils::result<void, utils::error> test_connection::open() {
|
||||||
is_open_ = true;
|
is_open_ = true;
|
||||||
|
const auto user = info().user;
|
||||||
return utils::ok<void>();
|
return utils::ok<void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue