summaryrefslogtreecommitdiff
path: root/src/database/datetime_writer.hpp
blob: b104911e5452b80525cedb7d20678ba2487f894c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
};