connection info in connection pool progress

This commit is contained in:
Sascha Kühl 2025-10-02 16:12:21 +02:00
parent 12905e3df3
commit 5490e67ecf
6 changed files with 15 additions and 11 deletions

View File

@ -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;
};

View File

@ -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_);

View File

@ -2,9 +2,10 @@
#include <chrono>
#include <thread>
#include <utility>
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);

View File

@ -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);

View File

@ -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();
}
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();

View File

@ -19,6 +19,7 @@ test_connection::test_connection(const sql::connection_info &info)
utils::result<void, utils::error> test_connection::open() {
is_open_ = true;
const auto user = info().user;
return utils::ok<void>();
}