summaryrefslogtreecommitdiff
path: root/lib/output
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-05-22 14:01:04 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-05-22 14:01:04 +0100
commitaf32ac991f1dd3d9138227436b5759889c1aaf77 (patch)
tree5af019a48d06ee943e3debac0eff3c0be073cc8f /lib/output
parentAdd test file for odds and ends (diff)
downloadmygrate-af32ac991f1dd3d9138227436b5759889c1aaf77.tar.bz2
mygrate-af32ac991f1dd3d9138227436b5759889c1aaf77.tar.xz
mygrate-af32ac991f1dd3d9138227436b5759889c1aaf77.zip
Move everything into more sensible places
Diffstat (limited to 'lib/output')
-rw-r--r--lib/output/dumpToConsole.cpp81
-rw-r--r--lib/output/dumpToConsole.h23
2 files changed, 104 insertions, 0 deletions
diff --git a/lib/output/dumpToConsole.cpp b/lib/output/dumpToConsole.cpp
new file mode 100644
index 0000000..6ece800
--- /dev/null
+++ b/lib/output/dumpToConsole.cpp
@@ -0,0 +1,81 @@
+#include "dumpToConsole.h"
+#include "../compileTimeFormatter.h"
+#include "../row.h"
+#include "../streamSupport.h"
+
+namespace MyGrate::Output {
+ void
+ DumpToConsole::tableMap(MyGrate::MariaDB_Event_Ptr event)
+ {
+ const auto & tm = event->event.table_map;
+ AdHoc::scprintf<"Table map %?.%? -> %?\n">(std::cout, tm.database, tm.table, tm.table_id);
+ EventHandlerBase::tableMap(std::move(event));
+ }
+
+ void
+ DumpToConsole::insertRow(MyGrate::MariaDB_Event_Ptr event)
+ {
+ const auto & rs = event->event.rows;
+ AdHoc::scprintf<"Insert into %?\n">(std::cout, rs.table_id);
+ dumpRowData(event->event.rows);
+ }
+
+ void
+ DumpToConsole::updateRow(MyGrate::MariaDB_Event_Ptr event)
+ {
+ const auto & rs = event->event.rows;
+ AdHoc::scprintf<"Update %?\n">(std::cout, rs.table_id);
+ dumpRowPairData(event->event.rows);
+ }
+
+ void
+ DumpToConsole::deleteRow(MyGrate::MariaDB_Event_Ptr event)
+ {
+ const auto & rs = event->event.rows;
+ AdHoc::scprintf<"Delete from %?\n">(std::cout, rs.table_id);
+ dumpRowData(event->event.rows);
+ }
+
+ struct write {
+ template<typename T>
+ void
+ operator()(const T & v) const
+ {
+ AdHoc::scprintf<"\t\t%?\n">(std::cout, v);
+ }
+
+ void
+ operator()(const uint8_t & v) const
+ {
+ AdHoc::scprintf<"\t\t%d\n">(std::cout, v);
+ }
+
+ void
+ operator()(const int8_t & v) const
+ {
+ AdHoc::scprintf<"\t\t%d\n">(std::cout, v);
+ }
+ };
+
+ void
+ DumpToConsole::dumpRowData(const st_mariadb_rpl_rows_event & row) const
+ {
+ Row r {row, tableMaps.at(row.table_id)->event.table_map};
+ std::for_each(r.begin(), r.end(), [](auto && fv) {
+ std::visit(write {}, fv);
+ });
+ }
+
+ void
+ DumpToConsole::dumpRowPairData(const st_mariadb_rpl_rows_event & row) const
+ {
+ RowPair rp {row, tableMaps.at(row.table_id)->event.table_map};
+ std::for_each(rp.first.begin(), rp.first.end(), [](auto && fv) {
+ std::visit(write {}, fv);
+ });
+ std::for_each(rp.second.begin(), rp.second.end(), [](auto && fv) {
+ std::visit(write {}, fv);
+ });
+ }
+
+}
diff --git a/lib/output/dumpToConsole.h b/lib/output/dumpToConsole.h
new file mode 100644
index 0000000..98769a6
--- /dev/null
+++ b/lib/output/dumpToConsole.h
@@ -0,0 +1,23 @@
+#ifndef MYGRATE_OUTPUT_DUMPTOCONSOLE_H
+#define MYGRATE_OUTPUT_DUMPTOCONSOLE_H
+
+#include "../eventHandlerBase.h"
+
+namespace MyGrate::Output {
+ class DumpToConsole : public MyGrate::EventHandlerBase {
+ protected:
+ void tableMap(MyGrate::MariaDB_Event_Ptr event) override;
+
+ void insertRow(MyGrate::MariaDB_Event_Ptr event) override;
+
+ void updateRow(MyGrate::MariaDB_Event_Ptr event) override;
+
+ void deleteRow(MyGrate::MariaDB_Event_Ptr event) override;
+
+ private:
+ void dumpRowData(const st_mariadb_rpl_rows_event & row) const;
+ void dumpRowPairData(const st_mariadb_rpl_rows_event & row) const;
+ };
+}
+
+#endif