-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdb_connection.h
More file actions
31 lines (23 loc) · 780 Bytes
/
db_connection.h
File metadata and controls
31 lines (23 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once
#include <sqlpp23/postgresql/postgresql.h>
class db_connection
{
private:
using pq_conn = sqlpp::postgresql::pooled_connection;
sqlpp::postgresql::connection_pool& m_pool;
// For C++17 or newer just use std::optional<pq_conn> m_conn;
std::unique_ptr<pq_conn> m_conn_ptr;
pq_conn& fetch();
public:
db_connection(sqlpp::postgresql::connection_pool& pool);
db_connection(const db_connection&) = delete;
db_connection(db_connection&&) = delete;
db_connection& operator=(const db_connection&) = delete;
db_connection& operator=(db_connection&&) = delete;
// Delegate any methods of sqlpp::postgresql::connection that you may need
template <typename T>
auto operator()(const T& t) -> decltype(fetch()(t))
{
return fetch()(t);
}
};