diff options
Diffstat (limited to 'lib/output/dumpToConsole.cpp')
-rw-r--r-- | lib/output/dumpToConsole.cpp | 81 |
1 files changed, 81 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); + }); + } + +} |