summaryrefslogtreecommitdiff
path: root/lib/output/pq
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-06-03 00:19:50 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-06-03 00:19:50 +0100
commit88708a8aa6a33f265ff990102b44a9a51e3bf4bb (patch)
tree8e59a73be6366e3237c473834852a276f07a9963 /lib/output/pq
parentDetermine parameter mode at point of call by DB type property (diff)
downloadmygrate-88708a8aa6a33f265ff990102b44a9a51e3bf4bb.tar.bz2
mygrate-88708a8aa6a33f265ff990102b44a9a51e3bf4bb.tar.xz
mygrate-88708a8aa6a33f265ff990102b44a9a51e3bf4bb.zip
Get upstream from DB
Adds options from command line and a few supporting tweaks
Diffstat (limited to 'lib/output/pq')
-rw-r--r--lib/output/pq/sql/selectSource.sql2
-rw-r--r--lib/output/pq/updateDatabase.cpp19
-rw-r--r--lib/output/pq/updateDatabase.h12
3 files changed, 25 insertions, 8 deletions
diff --git a/lib/output/pq/sql/selectSource.sql b/lib/output/pq/sql/selectSource.sql
index 3048410..db76b4a 100644
--- a/lib/output/pq/sql/selectSource.sql
+++ b/lib/output/pq/sql/selectSource.sql
@@ -1,3 +1,3 @@
-SELECT host, username, password, port, filename, position, serverid, table_schema
+SELECT host, username, password, port, filename, position, serverid
FROM mygrate.source s
WHERE s.id = $1
diff --git a/lib/output/pq/updateDatabase.cpp b/lib/output/pq/updateDatabase.cpp
index 77a9ce5..ebcabb3 100644
--- a/lib/output/pq/updateDatabase.cpp
+++ b/lib/output/pq/updateDatabase.cpp
@@ -1,8 +1,21 @@
#include "updateDatabase.h"
#include "pqConn.h"
-#include <string>
-#include <utility>
+#include <cstdint>
+#include <dbRecordSet.h>
+#include <eventSourceBase.h>
+#include <helpers.h>
+#include <memory>
+#include <output/pq/sql/selectSource.h>
+#include <stdexcept>
namespace MyGrate::Output::Pq {
- UpdateDatabase::UpdateDatabase(const char * const str, std::string p) : PqConn {str}, prefix {std::move(p)} { }
+ UpdateDatabase::UpdateDatabase(const char * const str, uint64_t s) : PqConn {str}, source {s} { }
+
+ EventSourceBasePtr
+ UpdateDatabase::getSource()
+ {
+ auto srcrec = output::pq::sql::selectSource::execute(this, source);
+ verify<std::runtime_error>(srcrec->rows() == 1, "Wrong number of source config rows");
+ return {};
+ }
}
diff --git a/lib/output/pq/updateDatabase.h b/lib/output/pq/updateDatabase.h
index bc54282..4e01d9c 100644
--- a/lib/output/pq/updateDatabase.h
+++ b/lib/output/pq/updateDatabase.h
@@ -2,15 +2,19 @@
#define MYGRATE_OUTPUT_PQ_UPDATEDATABASE_H
#include "pqConn.h"
-#include <string>
+#include <cstdint>
+#include <eventHandlerBase.h>
+#include <eventSourceBase.h>
namespace MyGrate::Output::Pq {
- class UpdateDatabase : PqConn {
+ class UpdateDatabase : public PqConn, public EventHandlerBase {
public:
- UpdateDatabase(const char * const str, std::string prefix);
+ UpdateDatabase(const char * const str, uint64_t source);
+
+ EventSourceBasePtr getSource();
private:
- std::string prefix;
+ uint64_t source;
};
}