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

Namespaces

namespace  sql_utils
 

Classes

class  AsyncStreamingResultSet
 Async streaming result set that yields rows asynchronously. More...
 
class  Connection
 Abstract base class for database connections. More...
 
struct  ConnectionError
 Error type for database connection operations. More...
 
struct  ConnectionPoolError
 Error type for connection pool operations. More...
 
struct  is_awaitable
 Helper trait to detect if a type is boost::asio::awaitable. More...
 
struct  is_awaitable< boost::asio::awaitable< T > >
 
class  PostgreSQLAsyncConnection
 Asynchronous PostgreSQL implementation of the Connection interface. More...
 
class  PostgreSQLAsyncStreamingSource
 Async PostgreSQL streaming data source for processing large result sets. More...
 
class  PostgreSQLConnection
 PostgreSQL implementation of the Connection interface. More...
 
struct  PostgreSQLConnectionParams
 Basic parameters for a PostgreSQL connection. More...
 
class  PostgreSQLConnectionPool
 PostgreSQL connection pool that manages a collection of PostgreSQL connections. More...
 
struct  PostgreSQLConnectionPoolConfig
 Configuration for PostgreSQL connection pool. More...
 
struct  PostgreSQLError
 Specialized ConnectionError for PostgreSQL with detailed error information. More...
 
class  PostgreSQLStatement
 Represents a prepared statement in PostgreSQL. More...
 
class  PostgreSQLStreamingSource
 PostgreSQL streaming data source for processing large result sets. More...
 
class  TransactionException
 Exception thrown when transaction operations fail. More...
 
class  TransactionGuard
 RAII wrapper for database transactions. More...
 

Typedefs

template<typename T >
using ConnectionResult = std::expected< T, ConnectionError >
 Type alias for result of connection operations.
 
template<typename T >
using ConnectionPoolResult = std::expected< T, ConnectionPoolError >
 Type alias for result of connection pool operations.
 

Enumerations

enum class  IsolationLevel { ReadUncommitted , ReadCommitted , RepeatableRead , Serializable }
 Transaction isolation levels. More...
 
enum class  PostgreSQLErrorCode {
  ConnectionFailed = 1000 , ConnectionClosed = 1001 , ConnectionTimeout = 1002 , TransactionError = 2000 ,
  NoActiveTransaction = 2001 , TransactionAlreadyActive = 2002 , QueryFailed = 3000 , InvalidParameters = 3001 ,
  EmptyResult = 3002 , DuplicateKey = 23505 , ForeignKeyViolation = 23503 , CheckConstraintViolation = 23514 ,
  NotNullViolation = 23502 , Unknown = 9999
}
 PostgreSQL specific error codes. More...
 

Functions

template<typename T >
void convert_and_assign (T &target, const std::string &value)
 Convert a string value to the target type and assign it.
 
template<typename Tuple , size_t... Indices>
void apply_tuple_assignment (Tuple &tuple, const std::vector< std::string > &row, std::index_sequence< Indices... >)
 Helper function to perform the tuple assignment with index sequence.
 
template<typename Tuple >
void map_row_to_tuple (Tuple &tuple, const std::vector< std::string > &row)
 Helper function to map a result row to a tuple (and thus to a struct)
 
template<typename... Args>
AsyncStreamingResultSet< PostgreSQLAsyncStreamingSourcecreate_async_streaming_result (PostgreSQLAsyncConnection &connection, const std::string &sql, Args &&... args)
 Create an async streaming result set from a PostgreSQL async connection and query.
 
std::string format_error (const ConnectionPoolError &error)
 Format a ConnectionPoolError for exception messages.
 
template<typename... Args>
result::StreamingResultSet< PostgreSQLStreamingSourcecreate_streaming_result (PostgreSQLConnection &connection, const std::string &sql, Args &&... args)
 Create a streaming result set from a PostgreSQL connection and query.
 

Variables

template<typename T >
constexpr bool is_awaitable_v = is_awaitable<T>::value
 
const std::unordered_map< std::string, PostgreSQLErrorCodesql_state_map
 Map of SQL STATE codes to PostgreSQLErrorCode values.
 

Typedef Documentation

◆ ConnectionPoolResult

template<typename T >
using relx::connection::ConnectionPoolResult = typedef std::expected<T, ConnectionPoolError>

Type alias for result of connection pool operations.

Definition at line 55 of file postgresql_connection_pool.hpp.

◆ ConnectionResult

template<typename T >
using relx::connection::ConnectionResult = typedef std::expected<T, ConnectionError>

Type alias for result of connection operations.

Definition at line 29 of file connection.hpp.

Enumeration Type Documentation

◆ IsolationLevel

Transaction isolation levels.

Enumerator
ReadUncommitted 

Allows dirty reads.

ReadCommitted 

Prevents dirty reads.

RepeatableRead 

Prevents non-repeatable reads.

Serializable 

Highest isolation level, prevents phantom reads.

Definition at line 32 of file connection.hpp.

◆ PostgreSQLErrorCode

PostgreSQL specific error codes.

Enumerator
ConnectionFailed 
ConnectionClosed 
ConnectionTimeout 
TransactionError 
NoActiveTransaction 
TransactionAlreadyActive 
QueryFailed 
InvalidParameters 
EmptyResult 
DuplicateKey 
ForeignKeyViolation 
CheckConstraintViolation 
NotNullViolation 
Unknown 

Definition at line 9 of file postgresql_errors.hpp.

Function Documentation

◆ apply_tuple_assignment()

template<typename Tuple , size_t... Indices>
void relx::connection::apply_tuple_assignment ( Tuple &  tuple,
const std::vector< std::string > &  row,
std::index_sequence< Indices... >   
)

Helper function to perform the tuple assignment with index sequence.

Template Parameters
TupleThe tuple type
IndicesParameter pack for indices
Parameters
tupleThe tuple to assign to
rowThe data row
indicesIndex sequence for tuple elements

Definition at line 50 of file meta.hpp.

◆ convert_and_assign()

template<typename T >
void relx::connection::convert_and_assign ( T &  target,
const std::string &  value 
)

Convert a string value to the target type and assign it.

Template Parameters
TThe target type
Parameters
targetThe target variable
valueThe string value to convert

Definition at line 15 of file meta.hpp.

◆ create_async_streaming_result()

template<typename... Args>
AsyncStreamingResultSet< PostgreSQLAsyncStreamingSource > relx::connection::create_async_streaming_result ( PostgreSQLAsyncConnection connection,
const std::string &  sql,
Args &&...  args 
)

Create an async streaming result set from a PostgreSQL async connection and query.

Parameters
connectionAsync PostgreSQL connection to use
sqlSQL query to execute
paramsOptional query parameters
Returns
AsyncStreamingResultSet for processing large result sets incrementally

Definition at line 367 of file postgresql_async_streaming_source.hpp.

◆ create_streaming_result()

template<typename... Args>
result::StreamingResultSet< PostgreSQLStreamingSource > relx::connection::create_streaming_result ( PostgreSQLConnection connection,
const std::string &  sql,
Args &&...  args 
)

Create a streaming result set from a PostgreSQL connection and query.

Parameters
connectionPostgreSQL connection to use
sqlSQL query to execute
paramsOptional query parameters
Returns
StreamingResultSet for processing large result sets incrementally

Definition at line 116 of file postgresql_streaming_source.hpp.

◆ format_error()

std::string relx::connection::format_error ( const ConnectionPoolError error)
inline

Format a ConnectionPoolError for exception messages.

Definition at line 49 of file postgresql_connection_pool.hpp.

◆ map_row_to_tuple()

template<typename Tuple >
void relx::connection::map_row_to_tuple ( Tuple &  tuple,
const std::vector< std::string > &  row 
)

Helper function to map a result row to a tuple (and thus to a struct)

Template Parameters
TupleThe tuple type that corresponds to the struct fields
Parameters
tupleThe tuple to fill with values
rowThe database result row containing values

Definition at line 61 of file meta.hpp.

Variable Documentation

◆ is_awaitable_v

template<typename T >
constexpr bool relx::connection::is_awaitable_v = is_awaitable<T>::value
inlineconstexpr

Definition at line 28 of file postgresql_async_streaming_source.hpp.

◆ sql_state_map

const std::unordered_map<std::string, PostgreSQLErrorCode> relx::connection::sql_state_map
inline
Initial value:
= {
{"23505", PostgreSQLErrorCode::DuplicateKey},
{"23503", PostgreSQLErrorCode::ForeignKeyViolation},
{"23514", PostgreSQLErrorCode::CheckConstraintViolation},
{"23502", PostgreSQLErrorCode::NotNullViolation},
}

Map of SQL STATE codes to PostgreSQLErrorCode values.

Definition at line 82 of file postgresql_errors.hpp.