ORE Studio 0.0.4
Loading...
Searching...
No Matches
bitemporal_operations.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_DATABASE_REPOSITORY_BITEMPORAL_OPERATIONS_HPP
21#define ORES_DATABASE_REPOSITORY_BITEMPORAL_OPERATIONS_HPP
22
23#include <map>
24#include <optional>
25#include <vector>
26#include <sqlgen/postgres.hpp>
27#include "ores.utility/log/make_logger.hpp"
28#include "ores.database/domain/context.hpp"
29#include "ores.database/repository/helpers.hpp"
30
31namespace ores::database::repository {
32
63template<typename EntityType, typename DomainType, typename QueryType, typename MapperFunc>
64std::vector<DomainType> execute_read_query(context ctx, const QueryType& query,
65 MapperFunc&& mapper, utility::log::logger_t& lg, const std::string& operation_desc) {
66
67 using namespace ores::utility::log;
68 using namespace sqlgen;
69
70 BOOST_LOG_SEV(lg, debug) << operation_desc << ".";
71
72 const auto r = session(ctx.connection_pool()).and_then(query);
73 ensure_success(r, lg);
74
75 BOOST_LOG_SEV(lg, debug) << operation_desc << ". Total: " << r->size();
76 return std::forward<MapperFunc>(mapper)(*r);
77}
78
101template<typename EntityType>
102void execute_write_query(context ctx, const EntityType& entity,
103 utility::log::logger_t& lg, const std::string& operation_desc) {
104
105 using namespace ores::utility::log;
106 using namespace sqlgen;
107
108 BOOST_LOG_SEV(lg, debug) << operation_desc << ".";
109
110 const auto r = session(ctx.connection_pool())
111 .and_then(begin_transaction)
112 .and_then(insert(entity))
113 .and_then(commit);
114 ensure_success(r, lg);
115
116 BOOST_LOG_SEV(lg, debug) << "Finished " << operation_desc << ".";
117}
118
138template<typename QueryType>
139void execute_delete_query(context ctx, const QueryType& query,
140 utility::log::logger_t& lg, const std::string& operation_desc) {
141
142 using namespace ores::utility::log;
143 using namespace sqlgen;
144
145 BOOST_LOG_SEV(lg, debug) << operation_desc << ".";
146
147 const auto r = session(ctx.connection_pool())
148 .and_then(begin_transaction)
149 .and_then(query)
150 .and_then(commit);
151 ensure_success(r, lg);
152
153 BOOST_LOG_SEV(lg, debug) << "Finished " << operation_desc << ".";
154}
155
173std::vector<std::string> execute_raw_string_query(context ctx,
174 const std::string& sql, utility::log::logger_t& lg,
175 const std::string& operation_desc);
176
195std::map<std::string, std::vector<std::string>> execute_raw_grouped_query(
196 context ctx, const std::string& sql, utility::log::logger_t& lg,
197 const std::string& operation_desc);
198
221std::vector<std::vector<std::optional<std::string>>> execute_raw_multi_column_query(
222 context ctx, const std::string& sql, utility::log::logger_t& lg,
223 const std::string& operation_desc);
224
225}
226
227#endif
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30