csvzall 0.4.0
CSV command-line tool and emerging C++ library
Loading...
Searching...
No Matches
postgres_connection.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef CSVZALL_HAVE_POSTGRESQL
4
5#include <pqxx/pqxx>
6
7#include <string>
8
9namespace csvzall::postgres {
10
11// PostgreSQL connection options
13 std::string host = "localhost";
14 int port = 5432;
15 std::string database;
16 std::string user;
17 std::string password;
18
19 // Build a libpq connection string consumed by pqxx::connection.
20 std::string to_connection_string() const;
21};
22
23// Thin RAII wrapper around pqxx::connection.
25 public:
28
33
34 [[nodiscard]] pqxx::connection& connection() { return connection_; }
35 [[nodiscard]] const pqxx::connection& connection() const { return connection_; }
36
37 [[nodiscard]] bool is_open() const { return connection_.is_open(); }
38
39 private:
40 pqxx::connection connection_;
41};
42
43[[nodiscard]] bool TableExists(pqxx::connection& conn, const std::string& table_name);
44
45void DropTableIfExists(pqxx::connection& conn, const std::string& table_name);
46
47[[nodiscard]] std::string QuoteIdentifier(const std::string& identifier);
48
49} // namespace csvzall::postgres
50
51namespace csvzall::pipeline {
52namespace postgres = ::csvzall::postgres;
53}
54
55#endif // CSVZALL_HAVE_POSTGRESQL
Definition postgres_connection.hpp:24
const pqxx::connection & connection() const
Definition postgres_connection.hpp:35
bool is_open() const
Definition postgres_connection.hpp:37
PostgresConnection(const PostgresConnection &)=delete
PostgresConnection & operator=(const PostgresConnection &)=delete
PostgresConnection(PostgresConnection &&) noexcept=default
pqxx::connection & connection()
Definition postgres_connection.hpp:34
std::vector< JsonValue > array
Definition json_extract.cpp:33
Definition chart_spec.hpp:100
Definition commands.hpp:16
void DropTableIfExists(pqxx::connection &conn, const std::string &table_name)
Definition postgres_connection.cpp:55
bool TableExists(pqxx::connection &conn, const std::string &table_name)
Definition postgres_connection.cpp:44
std::string QuoteIdentifier(const std::string &identifier)
Definition postgres_connection.cpp:29
Definition postgres_connection.hpp:12
std::string to_connection_string() const
Definition postgres_connection.cpp:10
std::string user
Definition postgres_connection.hpp:16
std::string host
Definition postgres_connection.hpp:13
std::string password
Definition postgres_connection.hpp:17
std::string database
Definition postgres_connection.hpp:15
int port
Definition postgres_connection.hpp:14