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

Asynchronous PostgreSQL implementation of the Connection interface. More...

#include <relx/connection/postgresql_async_connection.hpp>

Public Member Functions

 PostgreSQLAsyncConnection (boost::asio::io_context &io_context, std::string connection_string)
 Constructor with connection parameters and io_context.
 
 PostgreSQLAsyncConnection (boost::asio::io_context &io_context, const PostgreSQLConnectionParams &params)
 Constructor with structured connection parameters and io_context.
 
 ~PostgreSQLAsyncConnection ()
 Destructor that ensures proper cleanup.
 
 PostgreSQLAsyncConnection (const PostgreSQLAsyncConnection &)=delete
 
PostgreSQLAsyncConnectionoperator= (const PostgreSQLAsyncConnection &)=delete
 
 PostgreSQLAsyncConnection (PostgreSQLAsyncConnection &&) noexcept
 
PostgreSQLAsyncConnectionoperator= (PostgreSQLAsyncConnection &&) noexcept
 
bool is_connected () const
 Check if the connection is open.
 
bool in_transaction () const
 Check if a transaction is currently active.
 
boost::asio::awaitable< ConnectionResult< void > > connect ()
 Connect to the PostgreSQL database asynchronously.
 
boost::asio::awaitable< ConnectionResult< void > > disconnect ()
 Disconnect from the PostgreSQL database asynchronously.
 
boost::asio::awaitable< ConnectionResult< result::ResultSet > > execute_raw (std::string sql, std::vector< std::string > params={})
 Execute a raw SQL query with parameters asynchronously.
 
template<query::SqlExpr Query>
boost::asio::awaitable< ConnectionResult< result::ResultSet > > execute (Query query)
 Execute a query expression asynchronously.
 
template<typename T , query::SqlExpr Query>
boost::asio::awaitable< ConnectionResult< T > > execute (Query query)
 Execute a query and map results to a user-defined type asynchronously.
 
template<typename T , query::SqlExpr Query>
boost::asio::awaitable< ConnectionResult< std::vector< T > > > execute_many (const Query &query)
 Execute a query and map results to a vector of user-defined types asynchronously.
 
boost::asio::awaitable< ConnectionResult< void > > begin_transaction (IsolationLevel isolation_level=IsolationLevel::ReadCommitted)
 Begin a new transaction asynchronously.
 
boost::asio::awaitable< ConnectionResult< void > > commit_transaction ()
 Commit the current transaction asynchronously.
 
boost::asio::awaitable< ConnectionResult< void > > rollback_transaction ()
 Rollback the current transaction asynchronously.
 
pgsql_async_wrapper::Connectionget_async_conn ()
 Get the underlying async connection wrapper.
 
boost::asio::io_context & get_io_context () const
 Get the IO context associated with this connection.
 
boost::asio::awaitable< ConnectionResult< void > > reset_connection_state ()
 Reset connection state after streaming operations.
 
bool reset_connection_state_sync ()
 Reset connection state synchronously (for use in destructors)
 

Detailed Description

Asynchronous PostgreSQL implementation of the Connection interface.

Definition at line 27 of file postgresql_async_connection.hpp.

Constructor & Destructor Documentation

◆ PostgreSQLAsyncConnection() [1/4]

relx::connection::PostgreSQLAsyncConnection::PostgreSQLAsyncConnection ( boost::asio::io_context &  io_context,
std::string  connection_string 
)
explicit

Constructor with connection parameters and io_context.

Parameters
io_contextBoost.Asio IO context for async operations
connection_stringPostgreSQL connection string (e.g. "host=localhost port=5432 dbname=mydb user=postgres password=password")

◆ PostgreSQLAsyncConnection() [2/4]

relx::connection::PostgreSQLAsyncConnection::PostgreSQLAsyncConnection ( boost::asio::io_context &  io_context,
const PostgreSQLConnectionParams params 
)
explicit

Constructor with structured connection parameters and io_context.

Parameters
io_contextBoost.Asio IO context for async operations
paramsPostgreSQL connection parameters

◆ ~PostgreSQLAsyncConnection()

relx::connection::PostgreSQLAsyncConnection::~PostgreSQLAsyncConnection ( )

Destructor that ensures proper cleanup.

◆ PostgreSQLAsyncConnection() [3/4]

relx::connection::PostgreSQLAsyncConnection::PostgreSQLAsyncConnection ( const PostgreSQLAsyncConnection )
delete

◆ PostgreSQLAsyncConnection() [4/4]

relx::connection::PostgreSQLAsyncConnection::PostgreSQLAsyncConnection ( PostgreSQLAsyncConnection &&  )
noexcept

Member Function Documentation

◆ begin_transaction()

boost::asio::awaitable< ConnectionResult< void > > relx::connection::PostgreSQLAsyncConnection::begin_transaction ( IsolationLevel  isolation_level = IsolationLevel::ReadCommitted)

Begin a new transaction asynchronously.

Parameters
isolation_levelThe isolation level for the transaction
Returns
Awaitable that resolves when transaction begins

◆ commit_transaction()

boost::asio::awaitable< ConnectionResult< void > > relx::connection::PostgreSQLAsyncConnection::commit_transaction ( )

Commit the current transaction asynchronously.

Returns
Awaitable that resolves when transaction is committed

◆ connect()

boost::asio::awaitable< ConnectionResult< void > > relx::connection::PostgreSQLAsyncConnection::connect ( )

Connect to the PostgreSQL database asynchronously.

Returns
Awaitable that resolves when connection is established

◆ disconnect()

boost::asio::awaitable< ConnectionResult< void > > relx::connection::PostgreSQLAsyncConnection::disconnect ( )

Disconnect from the PostgreSQL database asynchronously.

Returns
Awaitable that resolves when disconnection is complete

◆ execute() [1/2]

template<query::SqlExpr Query>
boost::asio::awaitable< ConnectionResult< result::ResultSet > > relx::connection::PostgreSQLAsyncConnection::execute ( Query  query)
inline

Execute a query expression asynchronously.

Parameters
queryThe query expression to execute
Returns
Awaitable that resolves with the query results

Definition at line 84 of file postgresql_async_connection.hpp.

◆ execute() [2/2]

template<typename T , query::SqlExpr Query>
boost::asio::awaitable< ConnectionResult< T > > relx::connection::PostgreSQLAsyncConnection::execute ( Query  query)
inline

Execute a query and map results to a user-defined type asynchronously.

Template Parameters
TThe user-defined type to map results to
QueryThe query expression type
Parameters
queryThe query expression to execute
Returns
Awaitable that resolves with the mapped data

Definition at line 96 of file postgresql_async_connection.hpp.

◆ execute_many()

template<typename T , query::SqlExpr Query>
boost::asio::awaitable< ConnectionResult< std::vector< T > > > relx::connection::PostgreSQLAsyncConnection::execute_many ( const Query &  query)
inline

Execute a query and map results to a vector of user-defined types asynchronously.

Template Parameters
TThe user-defined type to map results to
QueryThe query expression type
Parameters
queryThe query expression to execute
Returns
Awaitable that resolves with a vector of mapped data

Definition at line 163 of file postgresql_async_connection.hpp.

◆ execute_raw()

boost::asio::awaitable< ConnectionResult< result::ResultSet > > relx::connection::PostgreSQLAsyncConnection::execute_raw ( std::string  sql,
std::vector< std::string >  params = {} 
)

Execute a raw SQL query with parameters asynchronously.

Parameters
sqlThe SQL query string
paramsVector of parameter values
Returns
Awaitable that resolves with the query results

◆ get_async_conn()

pgsql_async_wrapper::Connection & relx::connection::PostgreSQLAsyncConnection::get_async_conn ( )
inline

Get the underlying async connection wrapper.

Returns
Reference to the async wrapper connection

Definition at line 241 of file postgresql_async_connection.hpp.

◆ get_io_context()

boost::asio::io_context & relx::connection::PostgreSQLAsyncConnection::get_io_context ( ) const
inline

Get the IO context associated with this connection.

Definition at line 244 of file postgresql_async_connection.hpp.

◆ in_transaction()

bool relx::connection::PostgreSQLAsyncConnection::in_transaction ( ) const

Check if a transaction is currently active.

Returns
True if a transaction is active, false otherwise

◆ is_connected()

bool relx::connection::PostgreSQLAsyncConnection::is_connected ( ) const

Check if the connection is open.

Returns
True if connected, false otherwise

◆ operator=() [1/2]

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

◆ operator=() [2/2]

PostgreSQLAsyncConnection & relx::connection::PostgreSQLAsyncConnection::operator= ( PostgreSQLAsyncConnection &&  )
noexcept

◆ reset_connection_state()

boost::asio::awaitable< ConnectionResult< void > > relx::connection::PostgreSQLAsyncConnection::reset_connection_state ( )

Reset connection state after streaming operations.

Returns
Awaitable that resolves when the connection is ready for new commands

◆ reset_connection_state_sync()

bool relx::connection::PostgreSQLAsyncConnection::reset_connection_state_sync ( )

Reset connection state synchronously (for use in destructors)

Returns
True if reset was successful, false otherwise

This is a non-blocking version that can be called from destructors when async streaming result sets go out of scope before completion

◆ rollback_transaction()

boost::asio::awaitable< ConnectionResult< void > > relx::connection::PostgreSQLAsyncConnection::rollback_transaction ( )

Rollback the current transaction asynchronously.

Returns
Awaitable that resolves when transaction is rolled back

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