From 5490e67ecf570c02f84e2b1fa86b626da7081e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20K=C3=BChl?= Date: Thu, 2 Oct 2025 16:12:21 +0200 Subject: [PATCH] connection info in connection pool progress --- include/matador/sql/connection_pool.hpp | 2 +- source/orm/sql/connection.cpp | 3 ++- source/orm/sql/connection_pool.cpp | 8 ++++++-- test/backends/QueryTest.cpp | 4 ++-- test/orm/backend/test_backend_service.cpp | 8 +++----- test/orm/backend/test_connection.cpp | 1 + 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/matador/sql/connection_pool.hpp b/include/matador/sql/connection_pool.hpp index c38b430..7aeee18 100644 --- a/include/matador/sql/connection_pool.hpp +++ b/include/matador/sql/connection_pool.hpp @@ -15,7 +15,7 @@ namespace matador::sql { class connection_pool; struct identifiable_connection { - identifiable_connection(size_t id, connection &&conn); + identifiable_connection(size_t id, connection conn); size_t id{}; connection conn; }; diff --git a/source/orm/sql/connection.cpp b/source/orm/sql/connection.cpp index b9ce757..c020803 100644 --- a/source/orm/sql/connection.cpp +++ b/source/orm/sql/connection.cpp @@ -62,7 +62,8 @@ connection &connection::operator=(const connection &x) { connection::connection( connection&& x ) noexcept : connection_info_(std::move(x.connection_info_)) , connection_(std::move(x.connection_)) -, logger_(std::move(x.logger_)) {} +, logger_(std::move(x.logger_)) +{} connection & connection::operator=(connection &&x) noexcept { connection_info_ = std::move(x.connection_info_); diff --git a/source/orm/sql/connection_pool.cpp b/source/orm/sql/connection_pool.cpp index cea5f02..64c07e6 100644 --- a/source/orm/sql/connection_pool.cpp +++ b/source/orm/sql/connection_pool.cpp @@ -2,9 +2,10 @@ #include #include +#include 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) , conn(std::move(conn)){} @@ -58,7 +59,10 @@ connection_pool::connection_pool(const std::string& dns, size_t count) connection_repo_.reserve(count); while (count) { 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_}); auto &conn = connection_repo_.back(); idle_connections_.emplace(conn.id, &conn); diff --git a/test/backends/QueryTest.cpp b/test/backends/QueryTest.cpp index 04785c3..116d907 100644 --- a/test/backends/QueryTest.cpp +++ b/test/backends/QueryTest.cpp @@ -459,10 +459,10 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with many to many relationship" { 9, 3 } }; - for (const auto &ri: recipe_ingredients) { + for (const auto & [recipe_id, ingredient_id]: recipe_ingredients) { res = query::insert() .into("recipe_ingredients", column_generator::generate(repo, "recipe_ingredients", true)) - .values({ri.first, ri.second}) + .values({recipe_id, ingredient_id}) .execute(db); REQUIRE(res.is_ok()); REQUIRE(*res == 1); diff --git a/test/orm/backend/test_backend_service.cpp b/test/orm/backend/test_backend_service.cpp index 0cbd57d..8885fc0 100644 --- a/test/orm/backend/test_backend_service.cpp +++ b/test/orm/backend/test_backend_service.cpp @@ -11,9 +11,8 @@ sql::connection_impl *test_backend_service::create(const sql::connection_info &i return noop_connections_.insert(std::make_unique(info)).first->get(); } -void test_backend_service::destroy(sql::connection_impl *impl) -{ - auto it = std::find_if(noop_connections_.begin(), noop_connections_.end(), [impl](const auto &item) { +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) { return impl == item.get(); }); 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() .create() .build(); diff --git a/test/orm/backend/test_connection.cpp b/test/orm/backend/test_connection.cpp index 556f367..0c75411 100644 --- a/test/orm/backend/test_connection.cpp +++ b/test/orm/backend/test_connection.cpp @@ -19,6 +19,7 @@ test_connection::test_connection(const sql::connection_info &info) utils::result test_connection::open() { is_open_ = true; + const auto user = info().user; return utils::ok(); }