droplet 1.1.0
A multipurpose Discord bot with the hacker in mind
Loading...
Searching...
No Matches
RowDTOAdapter.hpp
Go to the documentation of this file.
1/*
2 * (c) Copyright dropsoft.org - All rights reserved
3 * Author: Erarnitox <david@erarnitox.de>
4 *
5 * License: MIT License
6 *
7 * Description: This class represents a generic
8 * DTO Interface. That can be used by other DTOs.
9 * It acts as an adapter to the pqxx rows and isolated the
10 * dependency on the pqxx library away from the DTOs
11 *
12 * Documentation: https://droplet.erarnitox.de/doxygen/html/RowDTOAdapter
13 */
14
15#pragma once
16
17#include <pqxx/pqxx>
18
19// Adapter class to convert pqxx::row to GenericDTO
21 private:
22 const pqxx::row row_;
23
24 public:
25 RowDTOAdapter(const pqxx::row& row) : row_(row) {
26 }
27
36 template <typename T>
37 T get(const std::string& field_name) const {
38 try {
39 return this->row_[field_name].as<T>();
40 } catch (...) {
41 return T{};
42 }
43 }
44};
Definition RowDTOAdapter.hpp:20
T get(const std::string &field_name) const
get the value of a field with the specified name
Definition RowDTOAdapter.hpp:37
RowDTOAdapter(const pqxx::row &row)
Definition RowDTOAdapter.hpp:25