summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-06-05 11:09:13 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-06-05 13:05:13 +0100
commit5956203258880a25d1705734e2bf57eb7a60a90c (patch)
treea844a5ce1784ac26cdc1300b7496ad2bcdd7da35
parentGet upstream from DB (diff)
downloadmygrate-5956203258880a25d1705734e2bf57eb7a60a90c.tar.bz2
mygrate-5956203258880a25d1705734e2bf57eb7a60a90c.tar.xz
mygrate-5956203258880a25d1705734e2bf57eb7a60a90c.zip
Wrap DbValue in a class so we can add helpers to it
-rw-r--r--lib/dbTypes.h22
-rw-r--r--lib/input/mysqlBindings.h2
-rw-r--r--lib/output/dumpToConsole.cpp6
-rw-r--r--lib/output/pq/pqBindings.h2
4 files changed, 26 insertions, 6 deletions
diff --git a/lib/dbTypes.h b/lib/dbTypes.h
index b35b036..068d642 100644
--- a/lib/dbTypes.h
+++ b/lib/dbTypes.h
@@ -33,8 +33,28 @@ namespace MyGrate {
};
using Blob = std::span<const std::byte>;
- using DbValue = std::variant<std::nullptr_t, double, float, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
+ using DbValueV = std::variant<std::nullptr_t, double, float, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
int64_t, uint64_t, timespec, Date, Time, DateTime, std::string_view, BitSet, Blob>;
+
+ class DbValue : public DbValueV {
+ public:
+ using DbValueV::DbValueV;
+ using DbValueV::operator=;
+
+ template<typename V>
+ inline auto
+ visit(V && v) const
+ {
+ return std::visit(std::forward<V>(v), static_cast<const DbValueV &>(*this));
+ }
+
+ template<typename T>
+ inline const auto &
+ get() const
+ {
+ return std::get<T>(static_cast<const DbValueV &>(*this));
+ }
+ };
}
#endif
diff --git a/lib/input/mysqlBindings.h b/lib/input/mysqlBindings.h
index dcb3ebf..569aeb5 100644
--- a/lib/input/mysqlBindings.h
+++ b/lib/input/mysqlBindings.h
@@ -23,7 +23,7 @@ namespace MyGrate::Input {
binds.reserve(vs.size());
data.reserve(vs.size());
for (const auto & v : vs) {
- std::visit(*this, v);
+ v.visit(*this);
}
}
template<std::integral T>
diff --git a/lib/output/dumpToConsole.cpp b/lib/output/dumpToConsole.cpp
index 1085bb5..96850f3 100644
--- a/lib/output/dumpToConsole.cpp
+++ b/lib/output/dumpToConsole.cpp
@@ -71,7 +71,7 @@ namespace MyGrate::Output {
{
Row r {row, tableMaps.at(row.table_id)->event.table_map};
std::for_each(r.begin(), r.end(), [](auto && fv) {
- std::visit(write {}, fv);
+ fv.visit(write {});
});
}
@@ -80,10 +80,10 @@ namespace MyGrate::Output {
{
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);
+ fv.visit(write {});
});
std::for_each(rp.second.begin(), rp.second.end(), [](auto && fv) {
- std::visit(write {}, fv);
+ fv.visit(write {});
});
}
diff --git a/lib/output/pq/pqBindings.h b/lib/output/pq/pqBindings.h
index ef0df84..c63b286 100644
--- a/lib/output/pq/pqBindings.h
+++ b/lib/output/pq/pqBindings.h
@@ -16,7 +16,7 @@ namespace MyGrate::Output::Pq {
values.reserve(vs.size());
lengths.reserve(vs.size());
for (const auto & v : vs) {
- std::visit(*this, v);
+ v.visit(*this);
}
}
template<Stringable T>