Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
database_manager.h
Go to the documentation of this file.
1#ifndef DATABASE_MANAGER_H
2#define DATABASE_MANAGER_H
3
4#include <QObject>
5#include <pqxx/pqxx>
6
14class DatabaseManager final : public QObject {
15 Q_OBJECT
16
17public:
23 static DatabaseManager instance;
24 return &instance;
25 }
26
31 bool IsConnected() const {
32 return is_connected_;
33 }
34
35private:
43 explicit DatabaseManager(QObject *parent = nullptr);
44
49 ~DatabaseManager() override = default;
50
55
60
62 std::unique_ptr<pqxx::connection> connection_;
65};
66
67#endif // DATABASE_MANAGER_H
bool IsConnected() const
Checks if the connection to the database was successfully established.
Definition database_manager.h:31
bool is_connected_
Flag indicating whether the database connection is currently established.
Definition database_manager.h:64
~DatabaseManager() override=default
Private destructor. The unique_ptr automatically manages the pqxx::connection lifetime.
static DatabaseManager * GetInstance()
Gets the singleton instance of the DatabaseManager.
Definition database_manager.h:22
std::unique_ptr< pqxx::connection > connection_
Unique pointer managing the pqxx database connection object.
Definition database_manager.h:62
DatabaseManager & operator=(const DatabaseManager &)=delete
Deleted assignment operator to prevent assignment.
DatabaseManager(QObject *parent=nullptr)
Private constructor to enforce the singleton pattern. Attempts to establish the connection to the Pos...
Definition database_manager.cpp:5
DatabaseManager(const DatabaseManager &)=delete
Deleted copy constructor to prevent copying.