statement cache progress
This commit is contained in:
parent
94b1c356a5
commit
4504c783e1
|
|
@ -6,6 +6,7 @@
|
|||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
@ -48,8 +49,14 @@ public:
|
|||
Connection* operator->() { return &connection_->second; }
|
||||
Connection& operator*() { return connection_->second; }
|
||||
|
||||
[[nodiscard]] size_t id() const { return connection_->first; }
|
||||
|
||||
[[nodiscard]] std::optional<size_t> id() const
|
||||
{
|
||||
if (connection_) {
|
||||
return connection_->first;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
[[nodiscard]] bool valid() const { return connection_ != nullptr; }
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -27,15 +27,8 @@ public:
|
|||
data_type_traits<Type>::bind_value(binder(), pos, val);
|
||||
}
|
||||
|
||||
void bind(size_t pos, const char *value, size_t size)
|
||||
{
|
||||
data_type_traits<const char*>::bind_value(binder(), pos, value, size);
|
||||
}
|
||||
|
||||
void bind(size_t pos, std::string &val, size_t size)
|
||||
{
|
||||
data_type_traits<std::string>::bind_value(binder(), pos, val, size);
|
||||
}
|
||||
void bind(size_t pos, const char *value, size_t size);
|
||||
void bind(size_t pos, std::string &val, size_t size);
|
||||
|
||||
virtual void reset() = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,4 +6,14 @@ statement_impl::statement_impl(query_context query)
|
|||
: query_(std::move(query))
|
||||
{}
|
||||
|
||||
void statement_impl::bind(size_t pos, const char *value, size_t size)
|
||||
{
|
||||
data_type_traits<const char*>::bind_value(binder(), pos, value, size);
|
||||
}
|
||||
|
||||
void statement_impl::bind(size_t pos, std::string &val, size_t size)
|
||||
{
|
||||
data_type_traits<std::string>::bind_value(binder(), pos, val, size);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ TEST_CASE("Create connection pool", "[connection pool]") {
|
|||
|
||||
auto ptr = pool.acquire();
|
||||
REQUIRE(ptr.valid());
|
||||
REQUIRE(ptr.id() > 0);
|
||||
REQUIRE(ptr.id().value() > 0);
|
||||
REQUIRE(ptr->is_open());
|
||||
|
||||
REQUIRE(pool.idle() == 3);
|
||||
|
|
@ -48,3 +48,33 @@ TEST_CASE("Create connection pool", "[connection pool]") {
|
|||
REQUIRE(pool.idle() == 4);
|
||||
REQUIRE(pool.inuse() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Acquire connection by id", "[connection pool]") {
|
||||
using pool_t = connection_pool<connection>;
|
||||
|
||||
pool_t pool("sqlite://sqlite.db", 4);
|
||||
|
||||
REQUIRE(pool.size() == 4);
|
||||
REQUIRE(pool.idle() == 4);
|
||||
REQUIRE(pool.inuse() == 0);
|
||||
|
||||
auto ptr = pool.acquire();
|
||||
REQUIRE(ptr.valid());
|
||||
REQUIRE(ptr.id());
|
||||
REQUIRE(ptr.id().value() > 0);
|
||||
REQUIRE(ptr->is_open());
|
||||
|
||||
auto same_ptr = pool.acquire(ptr.id().value());
|
||||
|
||||
REQUIRE(!same_ptr.valid());
|
||||
|
||||
const auto connection_id = ptr.id().value();
|
||||
|
||||
pool.release(ptr);
|
||||
REQUIRE(!ptr.valid());
|
||||
|
||||
same_ptr = pool.acquire(connection_id);
|
||||
|
||||
REQUIRE(same_ptr.valid());
|
||||
REQUIRE(same_ptr.id() == connection_id);
|
||||
}
|
||||
Loading…
Reference in New Issue