20#ifndef ORES_DATABASE_REPOSITORY_MAPPER_HELPERS_HPP
21#define ORES_DATABASE_REPOSITORY_MAPPER_HELPERS_HPP
28#include <sqlgen/postgres.hpp>
29#include "ores.utility/log/make_logger.hpp"
31namespace ores::database::repository {
56template<
typename Source,
typename Dest,
typename MapFunc>
57std::vector<Dest> map_vector(
58 const std::vector<Source>& source,
60 utility::log::logger_t& lg,
61 const std::string& log_prefix) {
65 BOOST_LOG_SEV(lg, debug) <<
"Mapping " << log_prefix
66 <<
". Total: " << source.size();
68 std::vector<Dest> result;
69 result.reserve(source.size());
70 std::ranges::transform(source, std::back_inserter(result),
71 std::forward<MapFunc>(map_func));
73 BOOST_LOG_SEV(lg, debug) <<
"Mapped " << log_prefix <<
".";
89inline std::chrono::system_clock::time_point
90timestamp_to_timepoint(
const sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S">& ts) {
91 const auto str = ts.str();
93 std::istringstream ss(str);
94 ss >> std::get_time(&tm,
"%Y-%m-%d %H:%M:%S");
95 return std::chrono::system_clock::from_time_t(std::mktime(&tm));
111inline sqlgen::Timestamp<
"%Y-%m-%d %H:%M:%S">
112timepoint_to_timestamp(
const std::chrono::system_clock::time_point& tp,
113 utility::log::logger_t& lg) {
116 const auto s = std::format(
"{:%Y-%m-%d %H:%M:%S}", tp);
117 const auto r = sqlgen::Timestamp<
"%Y-%m-%d %H:%M:%S">::from_string(s);
119 BOOST_LOG_SEV(lg, error) <<
"Error converting timepoint to timestamp";
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30