summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/output/pq/pqConn.cpp27
-rw-r--r--lib/output/pq/pqConn.h20
-rw-r--r--lib/output/pq/updateDatabase.cpp8
-rw-r--r--lib/output/pq/updateDatabase.h17
4 files changed, 72 insertions, 0 deletions
diff --git a/lib/output/pq/pqConn.cpp b/lib/output/pq/pqConn.cpp
new file mode 100644
index 0000000..78cdc06
--- /dev/null
+++ b/lib/output/pq/pqConn.cpp
@@ -0,0 +1,27 @@
+#include "pqConn.h"
+#include <helpers.h>
+#include <stdexcept>
+
+namespace MyGrate::Output::Pq {
+ PqConn::PqConn(const char * const str) : conn {PQconnectdb(str)}
+ {
+ verify<std::runtime_error>(PQstatus(conn) == CONNECTION_OK, "Connection failure");
+ PQsetNoticeProcessor(conn, notice_processor, this);
+ }
+
+ PqConn::~PqConn()
+ {
+ PQfinish(conn);
+ }
+
+ void
+ PqConn::notice_processor(void * p, const char * n)
+ {
+ return static_cast<PqConn *>(p)->notice_processor(n);
+ }
+
+ void
+ PqConn::notice_processor(const char *) const
+ {
+ }
+}
diff --git a/lib/output/pq/pqConn.h b/lib/output/pq/pqConn.h
new file mode 100644
index 0000000..bcf30b6
--- /dev/null
+++ b/lib/output/pq/pqConn.h
@@ -0,0 +1,20 @@
+#ifndef MYGRATE_OUTPUT_PQ_PQCONN_H
+#define MYGRATE_OUTPUT_PQ_PQCONN_H
+
+#include <libpq-fe.h>
+
+namespace MyGrate::Output::Pq {
+ class PqConn {
+ public:
+ explicit PqConn(const char * const str);
+ virtual ~PqConn();
+
+ private:
+ static void notice_processor(void *, const char *);
+ virtual void notice_processor(const char *) const;
+
+ PGconn * const conn;
+ };
+}
+
+#endif
diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp
new file mode 100644
index 0000000..77a9ce5
--- /dev/null
+++ b/lib/output/pq/updateDatabase.cpp
@@ -0,0 +1,8 @@
+#include "updateDatabase.h"
+#include "pqConn.h"
+#include <string>
+#include <utility>
+
+namespace MyGrate::Output::Pq {
+ UpdateDatabase::UpdateDatabase(const char * const str, std::string p) : PqConn {str}, prefix {std::move(p)} { }
+}
diff --git a/lib/output/pq/updateDatabase.h b/lib/output/pq/updateDatabase.h
new file mode 100644
index 0000000..bc54282
--- /dev/null
+++ b/lib/output/pq/updateDatabase.h
@@ -0,0 +1,17 @@
+#ifndef MYGRATE_OUTPUT_PQ_UPDATEDATABASE_H
+#define MYGRATE_OUTPUT_PQ_UPDATEDATABASE_H
+
+#include "pqConn.h"
+#include <string>
+
+namespace MyGrate::Output::Pq {
+ class UpdateDatabase : PqConn {
+ public:
+ UpdateDatabase(const char * const str, std::string prefix);
+
+ private:
+ std::string prefix;
+ };
+}
+
+#endif