Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
PostgresClient.hpp
Go to the documentation of this file.
1#pragma once
2#include <string>
3#include <memory>
4#include <functional>
5#include <libpq-fe.h>
8
9namespace database {
10
14class PostgresClient : public std::enable_shared_from_this<PostgresClient> {
15public:
22 PostgresClient(network::Proactor* proactor, const std::string& conninfo);
24
30 void connect(std::function<void(bool success)> callback);
31
38 void query(const std::string& sql, std::function<void(const ResultSet& res)> callback);
39
40private:
41 void handle_connect(std::function<void(bool)> callback);
42 void handle_query(std::function<void(const ResultSet&)> callback);
43
44 network::Proactor* proactor_;
45 std::string conninfo_;
46 PGconn* conn_{nullptr};
47 bool connected_{false};
48};
49
50} // namespace database
An asynchronous PostgreSQL client using libpq and a network Proactor.
Definition PostgresClient.hpp:14
void connect(std::function< void(bool success)> callback)
Connects to the PostgreSQL database asynchronously.
Definition PostgresClient.cpp:16
void query(const std::string &sql, std::function< void(const ResultSet &res)> callback)
Executes a query asynchronously.
Definition PostgresClient.cpp:48
~PostgresClient()
Definition PostgresClient.cpp:9
Represents a generic, unified result set from a database query.
Definition ResultSet.hpp:111
Definition Proactor.hpp:8
Definition ConnectionPool.hpp:10