VSQLite++ 0.3
Loading...
Searching...
No Matches
sqlite::v2::connection_pool Class Reference

Thread-safe pool for leasing reusable SQLite connections. More...

#include <connection_pool.hpp>

Collaboration diagram for sqlite::v2::connection_pool:
Collaboration graph

Classes

class  lease

Public Types

using connection_factory = std::function<std::shared_ptr<connection>()>

Public Member Functions

 connection_pool (std::size_t capacity, connection_factory factory)
 Constructs a pool with a maximum capacity and a factory used to create new connections.
lease acquire ()
 Blocks until a connection is available and returns a scoped lease.
std::size_t capacity () const
 Maximum number of concurrent connections the pool will create.
std::size_t idle_count () const
 Number of idle connections currently waiting in the pool.
std::size_t created_count () const
 Number of connections that have been created so far.

Static Public Member Functions

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.

Private Member Functions

void release (std::shared_ptr< connection > conn)

Private Attributes

connection_factory factory_
std::size_t capacity_
std::size_t created_ = 0
std::mutex mutex_
std::condition_variable cv_
std::vector< std::shared_ptr< connection > > idle_

Friends

class lease

Detailed Description

Thread-safe pool for leasing reusable SQLite connections.

Definition at line 55 of file connection_pool.hpp.

Member Typedef Documentation

◆ connection_factory

using sqlite::v2::connection_pool::connection_factory = std::function<std::shared_ptr<connection>()>

Definition at line 57 of file connection_pool.hpp.

Constructor & Destructor Documentation

◆ connection_pool()

sqlite::v2::connection_pool::connection_pool ( std::size_t capacity,
connection_factory factory )

Constructs a pool with a maximum capacity and a factory used to create new connections.

References capacity().

Referenced by sqlite::v2::connection_pool::lease::lease().

Here is the call graph for this function:

Member Function Documentation

◆ acquire()

lease sqlite::v2::connection_pool::acquire ( )

Blocks until a connection is available and returns a scoped lease.

◆ capacity()

std::size_t sqlite::v2::connection_pool::capacity ( ) const

Maximum number of concurrent connections the pool will create.

Referenced by connection_pool().

◆ created_count()

std::size_t sqlite::v2::connection_pool::created_count ( ) const

Number of connections that have been created so far.

◆ idle_count()

std::size_t sqlite::v2::connection_pool::idle_count ( ) const

Number of idle connections currently waiting in the pool.

◆ make_factory()

connection_factory sqlite::v2::connection_pool::make_factory ( std::string db,
open_mode mode = open_mode::open_or_create,
filesystem_adapter_ptr fs = {} )
static

Helper that captures the parameters for creating connections inside a pool factory.

References sqlite::v2::open_or_create.

◆ release()

void sqlite::v2::connection_pool::release ( std::shared_ptr< connection > conn)
private

◆ lease

friend class lease
friend

Definition at line 111 of file connection_pool.hpp.

Member Data Documentation

◆ capacity_

std::size_t sqlite::v2::connection_pool::capacity_
private

Definition at line 115 of file connection_pool.hpp.

◆ created_

std::size_t sqlite::v2::connection_pool::created_ = 0
private

Definition at line 116 of file connection_pool.hpp.

◆ cv_

std::condition_variable sqlite::v2::connection_pool::cv_
private

Definition at line 118 of file connection_pool.hpp.

◆ factory_

connection_factory sqlite::v2::connection_pool::factory_
private

Definition at line 114 of file connection_pool.hpp.

◆ idle_

std::vector<std::shared_ptr<connection> > sqlite::v2::connection_pool::idle_
private

Definition at line 119 of file connection_pool.hpp.

◆ mutex_

std::mutex sqlite::v2::connection_pool::mutex_
mutableprivate

Definition at line 117 of file connection_pool.hpp.


The documentation for this class was generated from the following file: