relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
relx::connection::PostgreSQLConnectionPool Class Reference

PostgreSQL connection pool that manages a collection of PostgreSQL connections. More...

#include <relx/connection/postgresql_connection_pool.hpp>

Inheritance diagram for relx::connection::PostgreSQLConnectionPool:

Classes

class  PooledConnection
 A wrapper for a connection that automatically returns it to the pool. More...
 

Public Member Functions

 ~PostgreSQLConnectionPool ()
 Destructor that cleans up all connections.
 
 PostgreSQLConnectionPool (const PostgreSQLConnectionPool &)=delete
 
PostgreSQLConnectionPooloperator= (const PostgreSQLConnectionPool &)=delete
 
 PostgreSQLConnectionPool (PostgreSQLConnectionPool &&)=delete
 
PostgreSQLConnectionPooloperator= (PostgreSQLConnectionPool &&)=delete
 
ConnectionPoolResult< void > initialize ()
 Initialize the connection pool.
 
ConnectionPoolResult< PooledConnectionget_connection ()
 Get a connection from the pool with automatic return when out of scope.
 
size_t active_connections () const
 Get the current number of active connections.
 
size_t idle_connections () const
 Get the current number of idle connections.
 
template<typename Func >
auto with_connection (Func &&func) -> ConnectionPoolResult< std::invoke_result_t< Func, PooledConnection & > >
 Execute a function with a connection from the pool.
 

Static Public Member Functions

static std::shared_ptr< PostgreSQLConnectionPoolcreate (PostgreSQLConnectionPoolConfig config)
 Create a new connection pool.
 

Detailed Description

PostgreSQL connection pool that manages a collection of PostgreSQL connections.

Definition at line 61 of file postgresql_connection_pool.hpp.

Constructor & Destructor Documentation

◆ ~PostgreSQLConnectionPool()

relx::connection::PostgreSQLConnectionPool::~PostgreSQLConnectionPool ( )

Destructor that cleans up all connections.

◆ PostgreSQLConnectionPool() [1/2]

relx::connection::PostgreSQLConnectionPool::PostgreSQLConnectionPool ( const PostgreSQLConnectionPool )
delete

◆ PostgreSQLConnectionPool() [2/2]

relx::connection::PostgreSQLConnectionPool::PostgreSQLConnectionPool ( PostgreSQLConnectionPool &&  )
delete

Member Function Documentation

◆ active_connections()

size_t relx::connection::PostgreSQLConnectionPool::active_connections ( ) const

Get the current number of active connections.

Returns
The number of active connections

◆ create()

static std::shared_ptr< PostgreSQLConnectionPool > relx::connection::PostgreSQLConnectionPool::create ( PostgreSQLConnectionPoolConfig  config)
inlinestatic

Create a new connection pool.

Note
The pool needs to be a shared_ptr to help with pool worker lifetime management, so we only allow creation via the create() function.
Parameters
configConfiguration for the pool
Returns
Shared pointer to the new pool

Definition at line 83 of file postgresql_connection_pool.hpp.

◆ get_connection()

ConnectionPoolResult< PooledConnection > relx::connection::PostgreSQLConnectionPool::get_connection ( )

Get a connection from the pool with automatic return when out of scope.

Returns
Result containing a PooledConnection or an error

◆ idle_connections()

size_t relx::connection::PostgreSQLConnectionPool::idle_connections ( ) const

Get the current number of idle connections.

Returns
The number of idle connections

◆ initialize()

ConnectionPoolResult< void > relx::connection::PostgreSQLConnectionPool::initialize ( )

Initialize the connection pool.

Returns
Result indicating success or failure

◆ operator=() [1/2]

PostgreSQLConnectionPool & relx::connection::PostgreSQLConnectionPool::operator= ( const PostgreSQLConnectionPool )
delete

◆ operator=() [2/2]

PostgreSQLConnectionPool & relx::connection::PostgreSQLConnectionPool::operator= ( PostgreSQLConnectionPool &&  )
delete

◆ with_connection()

template<typename Func >
auto relx::connection::PostgreSQLConnectionPool::with_connection ( Func &&  func) -> ConnectionPoolResult<std::invoke_result_t<Func, PooledConnection&>>
inline

Execute a function with a connection from the pool.

Template Parameters
FuncType of the function to execute
Parameters
funcFunction to execute with a connection
Returns
Result of the function execution

Definition at line 119 of file postgresql_connection_pool.hpp.


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