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.logging/make_logger.hpp"
28#include "ores.database/domain/context.hpp"
29#include "ores.database/repository/helpers.hpp"
30
32
63template<typename EntityType, typename DomainType, typename QueryType, typename MapperFunc>
64std::vector<DomainType> execute_read_query(context ctx, const QueryType& query,
65 MapperFunc&& mapper, logging::logger_t& lg, const std::string& operation_desc) {
66
67 using namespace ores::logging;
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 logging::logger_t& lg, const std::string& operation_desc) {
104
105 using namespace ores::logging;
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 logging::logger_t& lg, const std::string& operation_desc) {
141
142 using namespace ores::logging;
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, logging::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, logging::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, logging::logger_t& lg,
223 const std::string& operation_desc);
224
241void execute_raw_command(context ctx, const std::string& sql,
242 logging::logger_t& lg, const std::string& operation_desc);
243
263std::vector<std::string> execute_parameterized_string_query(context ctx,
264 const std::string& sql, const std::vector<std::string>& params,
265 logging::logger_t& lg, const std::string& operation_desc);
266
290std::vector<std::string> execute_parameterized_string_query(
291 const sqlgen::postgres::Credentials& creds,
292 const std::string& sql, const std::vector<std::string>& params,
293 logging::logger_t& lg, const std::string& operation_desc);
294
315std::vector<std::vector<std::optional<std::string>>> execute_raw_multi_column_query(
316 const sqlgen::postgres::Credentials& creds,
317 const std::string& sql, logging::logger_t& lg,
318 const std::string& operation_desc);
319
339void execute_parameterized_command(context ctx, const std::string& sql,
340 const std::vector<std::string>& params, logging::logger_t& lg,
341 const std::string& operation_desc);
342
363std::vector<std::vector<std::optional<std::string>>> execute_parameterized_multi_column_query(
364 context ctx, const std::string& sql, const std::vector<std::string>& params,
365 logging::logger_t& lg, const std::string& operation_desc);
366
367}
368
369#endif
Repository infrastructure and bitemporal operations.
Definition bitemporal_operations.hpp:31
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:47
connection_pool_type & connection_pool()
Gets the tenant-aware connection pool.
Definition context.hpp:84