droplet 1.3.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 erarnitox.de - 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 "DatabaseBackend.hpp"
18
19// Adapter class to convert DatabaseRow to GenericDTO
21 private:
22 const NativeDatabase::Row row_;
23
24 public:
25 RowDTOAdapter(const NativeDatabase::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};
T get(const std::string &field_name) const
get the value of a field with the specified name
Definition RowDTOAdapter.hpp:37
RowDTOAdapter(const NativeDatabase::Row &row)
Definition RowDTOAdapter.hpp:25
pqxx::row Row
Definition DatabaseBackend.hpp:31