summaryrefslogtreecommitdiff
path: root/src/database/datetime_writer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/datetime_writer.hpp')
-rw-r--r--src/database/datetime_writer.hpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/database/datetime_writer.hpp b/src/database/datetime_writer.hpp
new file mode 100644
index 0000000..b104911
--- /dev/null
+++ b/src/database/datetime_writer.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <utils/datetime.hpp>
+#include <database/engine.hpp>
+
+#include <logger/logger.hpp>
+#include <database/postgresql_engine.hpp>
+#include <database/sqlite3_engine.hpp>
+
+class DatetimeWriter
+{
+public:
+ DatetimeWriter(DateTime datetime, const DatabaseEngine& engine):
+ datetime(datetime),
+ engine(engine)
+ {}
+
+ long double get_value() const
+ {
+ const long double epoch_duration = this->datetime.epoch().count();
+ const long double epoch_seconds = epoch_duration / std::chrono::system_clock::period::den;
+ return this->engine.epoch_to_floating_value(epoch_seconds);
+ }
+ std::string escape_param_number(int value) const
+ {
+ return this->engine.escape_param_number(value);
+ }
+
+private:
+ const DateTime datetime;
+ const DatabaseEngine& engine;
+};