29 [[nodiscard]]
static auto connect(
const std::string& db_name,
30 const std::string& user,
31 const std::string& password,
32 const std::string& host,
33 const std::string& port) -> bool;
35 [[nodiscard]]
static auto connect(
const std::string& connection_string) -> bool;
46template <
size_t I = 0,
typename... Types>
47constexpr void assignResults(
const pqxx::result& result, std::vector<std::variant<Types...>>& args) {
48 if constexpr (I <
sizeof...(Types)) {
49 args[I] = result.at(0, I).template get<std::variant_alternative_t<I, std::variant<Types...>>>().value();
50 assignResults<I + 1>(result, args);
61template <
typename... Types>
62[[nodiscard(
"You need to check if the Query was executed on the Database!")]]
auto execQuery(
const std::string& query,
63 Types&&... args)
noexcept
70 pqxx::result result = txn.exec_params(query, std::forward<Types>(args)...);
75 }
catch (
const pqxx::broken_connection& e) {
96template <
typename... Types>
103 pqxx::result result = txn.exec_params(query, std::forward<Types>(args)...);
109 }
catch (
const pqxx::broken_connection& e) {
113 return {pqxx::row()};
130template <
typename... Types>
131[[nodiscard]]
auto execSelectAll(
const std::string& query, Types&&... args)
noexcept -> std::vector<RowDTOAdapter> {
132 static int times = 0;
137 pqxx::result result = txn.exec_params(query, std::forward<Types>(args)...);
142 std::vector<RowDTOAdapter> selection;
143 for (
int i{0}; i < result.size(); ++i) {
144 selection.emplace_back(result[i]);
148 }
catch (
const pqxx::broken_connection& e) {
152 return {pqxx::row()};
Definition Database.hpp:25
static auto getConnection() noexcept -> pqxx::connection *
returns the database connection. Reconnects if the Database has no active connection
Definition Database.cpp:108
static auto reconnect() noexcept -> void
reconnects to the database server if the connection was lost
Definition Database.cpp:79
static auto disconnect() noexcept -> void
disconnect from a postgres database
Definition Database.cpp:61
static auto hasConnection() noexcept -> bool
checks if the database has an active connection
Definition Database.cpp:69
static auto connect(const std::string &db_name, const std::string &user, const std::string &password, const std::string &host, const std::string &port) -> bool
connect to a postgres database
Definition Database.cpp:33
Definition RowDTOAdapter.hpp:20
Definition Database.hpp:43
auto execSelect(const std::string &query, Types &&... args) noexcept -> RowDTOAdapter
executes a Select on the database
Definition Database.hpp:97
auto execSelectAll(const std::string &query, Types &&... args) noexcept -> std::vector< RowDTOAdapter >
executes a Select on the database
Definition Database.hpp:131
constexpr void assignResults(const pqxx::result &result, std::vector< std::variant< Types... > > &args)
Definition Database.hpp:47
auto execQuery(const std::string &query, Types &&... args) noexcept -> bool
executes a query on the database
Definition Database.hpp:62