32#ifndef GUARD_SQLITE_CONNECTION_POOL_HPP_INCLUDED
33#define GUARD_SQLITE_CONNECTION_POOL_HPP_INCLUDED
35#include <condition_variable>
73 std::shared_ptr<connection>
shared()
const;
78 std::shared_ptr<shared_state>
state_;
112 void release(std::shared_ptr<connection> conn);
118 std::condition_variable
cv_;
119 std::vector<std::shared_ptr<connection>>
idle_;
std::shared_ptr< connection > connection_
std::shared_ptr< connection > shared() const
lease(lease &&other) noexcept
lease(connection_pool *pool, std::shared_ptr< connection > conn)
lease & operator=(lease &&other) noexcept
std::shared_ptr< shared_state > state_
lease(lease const &)=delete
lease & operator=(lease const &)=delete
connection * operator->() const
connection & operator*() const
Thread-safe pool for leasing reusable SQLite connections.
std::size_t created_count() const
Number of connections that have been created so far.
connection_factory factory_
static connection_factory make_factory(std::string db, open_mode mode=open_mode::open_or_create, filesystem_adapter_ptr fs={})
Helper that captures the parameters for creating connections inside a pool factory.
lease acquire()
Blocks until a connection is available and returns a scoped lease.
void release(std::shared_ptr< connection > conn)
std::condition_variable cv_
std::vector< std::shared_ptr< connection > > idle_
std::function< std::shared_ptr< connection >()> connection_factory
connection_pool(std::size_t capacity, connection_factory factory)
Constructs a pool with a maximum capacity and a factory used to create new connections.
std::size_t idle_count() const
Number of idle connections currently waiting in the pool.
std::size_t capacity() const
Maximum number of concurrent connections the pool will create.
Owning RAII wrapper for sqlite3* handles plus attachment helpers and statement caching.
std::shared_ptr< filesystem_adapter > filesystem_adapter_ptr
@ open_or_create
Opens an existing database or creates it on demand.
connection is used to open, close, attach and detach a database. Further it has to be passed to all c...