implemented lazy loading for object_ptr and belongs_to

This commit is contained in:
2026-01-15 12:40:54 +01:00
parent db8e137c11
commit 7626331866
81 changed files with 1790 additions and 927 deletions
+9 -11
View File
@@ -53,21 +53,19 @@ bool connection_ptr::valid() const {
return connection_ != nullptr;
}
connection_pool::connection_pool(const std::string& dns, size_t count)
: info_(connection_info::parse(dns)) {
connection_pool::connection_pool(const std::string& dns, const size_t count)
: connection_pool(dns, count, [](const connection_info &info) { return connection{info}; })
{}
connection_pool::connection_pool(const std::string &dns, size_t count, std::function<connection(const connection_info &)> &&connection_creator)
: info_(connection_info::parse(dns))
, connection_creator_(std::move(connection_creator)) {
connection_repo_.reserve(count);
while (count) {
// connection c(info_);
// 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_creator_(info_));
auto &conn = connection_repo_.back();
idle_connections_.emplace(conn.id, &conn);
// Todo: handle result
const auto result = conn.conn.open();
if (!result) {
if (const auto result = conn.conn.open(); !result) {
throw std::runtime_error("Failed to open connection");
}
--count;