implemented lazy loading for object_ptr and belongs_to
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user