9#include <unordered_map>
36 void connect(std::function<
void(
bool success)> callback);
44 void query(
const std::string& sql, std::function<
void(
const ResultSet& res)> callback);
52 void query(
const std::string& sql,
const std::vector<std::optional<std::string>>& params,
53 std::function<
void(
const ResultSet& res)> callback);
63 void execute(
const std::string& sql,
const std::vector<std::optional<std::string>>& params,
64 std::function<
void(
const ResultSet& res)> callback);
89 void reconnect(std::function<
void(
bool success)> callback);
An asynchronous PostgreSQL client using libpq and a network Proactor.
Definition PostgresClient.hpp:19
void set_statement_timeout(std::chrono::milliseconds timeout)
Server-side limit on each statement's run time; zero = none.
Definition PostgresClient.hpp:84
void finish_connect(std::function< void(bool)> callback)
PostgresClient(network::Proactor *proactor, const std::string &conninfo)
Constructs a new PostgresClient.
size_t max_prepared_statements() const
Definition PostgresClient.hpp:92
std::chrono::milliseconds statement_timeout_
Definition PostgresClient.hpp:105
void rollback(std::function< void(const ResultSet &res)> callback)
Rolls back the current transaction (ROLLBACK).
void handle_query(std::function< void(const ResultSet &)> callback)
bool is_healthy() const
True if connected and libpq reports the connection usable.
std::unordered_map< std::string, std::string > prepared_
Definition PostgresClient.hpp:106
void execute(const std::string &sql, const std::vector< std::optional< std::string > > ¶ms, std::function< void(const ResultSet &res)> callback)
Like the parameterized query(), but prepares sql once per connection and reuses the plan on later cal...
void set_max_prepared_statements(size_t n)
Definition PostgresClient.hpp:91
void query(const std::string &sql, const std::vector< std::optional< std::string > > ¶ms, std::function< void(const ResultSet &res)> callback)
Executes a statement with $1, $2, ... placeholders bound to params (text format; std::nullopt binds S...
void begin(std::function< void(const ResultSet &res)> callback)
Starts a transaction (BEGIN).
std::string conninfo_
Definition PostgresClient.hpp:102
size_t next_statement_
Definition PostgresClient.hpp:107
void connect(std::function< void(bool success)> callback)
Connects to the PostgreSQL database asynchronously. Called on a connected client, it drops that conne...
size_t prepared_statement_count() const
Definition PostgresClient.hpp:93
void query(const std::string &sql, std::function< void(const ResultSet &res)> callback)
Executes a query asynchronously.
bool in_transaction() const
True inside a transaction block (including one that has failed).
void commit(std::function< void(const ResultSet &res)> callback)
PGconn * conn_
Definition PostgresClient.hpp:103
void handle_connect(std::function< void(bool)> callback)
bool connected_
Definition PostgresClient.hpp:104
network::Proactor * proactor_
Definition PostgresClient.hpp:101
void reconnect(std::function< void(bool success)> callback)
Drops the current connection (if any) and connects again.
size_t max_prepared_
Definition PostgresClient.hpp:108
Represents a generic, unified result set from a database query.
Definition ResultSet.hpp:197
Definition Proactor.hpp:9
Definition ConnectionPool.hpp:14