|
relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
|
PostgreSQL implementation of the Connection interface. More...
#include <relx/connection/postgresql_connection.hpp>
Public Member Functions | |
| PostgreSQLConnection (std::string_view connection_string) | |
| Constructor with connection parameters. | |
| PostgreSQLConnection (const PostgreSQLConnectionParams ¶ms) | |
| Constructor with structured connection parameters. | |
| ~PostgreSQLConnection () override | |
| Destructor that ensures proper cleanup. | |
| PostgreSQLConnection (const PostgreSQLConnection &)=delete | |
| PostgreSQLConnection & | operator= (const PostgreSQLConnection &)=delete |
| PostgreSQLConnection (PostgreSQLConnection &&) noexcept | |
| PostgreSQLConnection & | operator= (PostgreSQLConnection &&) noexcept |
| ConnectionResult< void > | connect () override |
| Connect to the PostgreSQL database. | |
| ConnectionResult< void > | disconnect () override |
| Disconnect from the PostgreSQL database. | |
| ConnectionResult< result::ResultSet > | execute_raw (const std::string &sql, const std::vector< std::string > ¶ms={}) override |
| Execute a raw SQL query with parameters. | |
| ConnectionResult< result::ResultSet > | execute_raw_binary (const std::string &sql, const std::vector< std::string > ¶ms, const std::vector< bool > &is_binary) |
| Execute a raw SQL query with binary parameters. | |
| template<typename... Args> | |
| ConnectionResult< result::ResultSet > | execute_typed (const std::string &sql, Args &&... args) |
| Execute a raw SQL query with typed parameters. | |
| bool | is_connected () const override |
| Check if the connection is open. | |
| ConnectionResult< void > | begin_transaction (IsolationLevel isolation_level=IsolationLevel::ReadCommitted) override |
| Begin a new transaction with specified isolation level. | |
| ConnectionResult< void > | commit_transaction () override |
| Commit the current transaction. | |
| ConnectionResult< void > | rollback_transaction () override |
| Rollback the current transaction. | |
| bool | in_transaction () const override |
| Check if a transaction is currently active. | |
| std::unique_ptr< PostgreSQLStatement > | prepare_statement (const std::string &name, const std::string &sql, int param_count) |
| Create a prepared statement. | |
| PGconn * | get_pg_conn () |
| Get direct access to the PostgreSQL connection. | |
Public Member Functions inherited from relx::connection::Connection | |
| virtual | ~Connection ()=default |
| Virtual destructor. | |
| template<query::SqlExpr Query> | |
| ConnectionResult< result::ResultSet > | execute (const Query &query) |
| Execute a query expression. | |
| template<typename T , query::SqlExpr Query> | |
| ConnectionResult< T > | execute (const Query &query) |
| Execute a query and map results to a user-defined type using Boost.PFR. | |
| template<typename T , query::SqlExpr Query> | |
| ConnectionResult< std::vector< T > > | execute_many (const Query &query) |
| Execute a query and map results to a vector of user-defined types. | |
Static Public Member Functions | |
| static std::string | convert_placeholders (const std::string &sql) |
| Convert SQL with ? placeholders to PostgreSQL's $n format. | |
PostgreSQL implementation of the Connection interface.
Definition at line 25 of file postgresql_connection.hpp.
|
explicit |
Constructor with connection parameters.
| connection_string | PostgreSQL connection string (e.g. "host=localhost port=5432 dbname=mydb user=postgres password=password") |
|
explicit |
Constructor with structured connection parameters.
| params | PostgreSQL connection parameters |
|
override |
Destructor that ensures proper cleanup.
|
delete |
|
noexcept |
|
overridevirtual |
Begin a new transaction with specified isolation level.
| isolation_level | The isolation level for the transaction |
Implements relx::connection::Connection.
|
overridevirtual |
Commit the current transaction.
Implements relx::connection::Connection.
|
overridevirtual |
Connect to the PostgreSQL database.
Implements relx::connection::Connection.
|
static |
Convert SQL with ? placeholders to PostgreSQL's $n format.
| sql | SQL query with ? placeholders |
|
overridevirtual |
Disconnect from the PostgreSQL database.
Implements relx::connection::Connection.
|
overridevirtual |
Execute a raw SQL query with parameters.
| sql | The SQL query string |
| params | Vector of parameter values |
Implements relx::connection::Connection.
| ConnectionResult< result::ResultSet > relx::connection::PostgreSQLConnection::execute_raw_binary | ( | const std::string & | sql, |
| const std::vector< std::string > & | params, | ||
| const std::vector< bool > & | is_binary | ||
| ) |
Execute a raw SQL query with binary parameters.
| sql | The SQL query string |
| params | Vector of parameter values |
| is_binary | Vector of flags indicating whether each parameter is binary |
|
inline |
Execute a raw SQL query with typed parameters.
| Args | The types of the parameters |
| sql | The SQL query string |
| args | The parameter values |
Definition at line 78 of file postgresql_connection.hpp.
|
inline |
Get direct access to the PostgreSQL connection.
Definition at line 148 of file postgresql_connection.hpp.
|
overridevirtual |
Check if a transaction is currently active.
Implements relx::connection::Connection.
|
overridevirtual |
Check if the connection is open.
Implements relx::connection::Connection.
|
delete |
|
noexcept |
| std::unique_ptr< PostgreSQLStatement > relx::connection::PostgreSQLConnection::prepare_statement | ( | const std::string & | name, |
| const std::string & | sql, | ||
| int | param_count | ||
| ) |
Create a prepared statement.
| name | The name of the prepared statement |
| sql | The SQL query text |
| param_count | The number of parameters in the statement |
|
overridevirtual |
Rollback the current transaction.
Implements relx::connection::Connection.