20#ifndef ORES_DATABASE_REPOSITORY_HELPERS_HPP
21#define ORES_DATABASE_REPOSITORY_HELPERS_HPP
25#include <boost/exception/diagnostic_information.hpp>
26#include <sqlgen/postgres.hpp>
27#include "ores.utility/log/make_logger.hpp"
28#include "ores.database/repository/repository_exception.hpp"
30namespace ores::database::repository {
39inline constexpr const char* MAX_TIMESTAMP =
"9999-12-31 23:59:59";
57void ensure_success(
const T& result, utility::log::logger_t& lg) {
61 BOOST_LOG_SEV(lg, error) << result.error().what();
62 BOOST_THROW_EXCEPTION(
63 repository_exception(std::format(
"Repository error: {}",
64 result.error().what())));
82inline auto make_timestamp(
const std::string& s, utility::log::logger_t& lg) {
85 const auto r = sqlgen::Timestamp<
"%Y-%m-%d %H:%M:%S">::from_string(s);
87 BOOST_LOG_SEV(lg, error) <<
"Error converting timestamp: '" << s
88 <<
"'. Error: " << r.error().what();
89 BOOST_THROW_EXCEPTION(
91 std::format(
"Timestamp conversion error: {}", s)));
110template<
typename EntityType>
111std::string generate_create_table_sql(utility::log::logger_t& lg) {
113 using namespace sqlgen;
115 const auto query = create_table<EntityType> | if_not_exists;
116 const auto sql = postgres::to_sql(query);
118 BOOST_LOG_SEV(lg, debug) << sql;
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30