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
|
#ifndef DATABASECONNECTIONMANAGER_H
#define DATABASECONNECTIONMANAGER_H
#include "DatabaseConnectionPool.h"
#include "common.h"
/// @brief RAII class for database connections
class DatabaseConnectionHandle
{
public:
DatabaseConnectionHandle(DatabaseConnectionPoolPtr dcp);
~DatabaseConnectionHandle();
DatabaseConnectionHandle(const DatabaseConnectionHandle&) = delete;
DatabaseConnectionHandle& operator=(const DatabaseConnectionHandle&) = delete;
DatabaseConnectionHandle(DatabaseConnectionHandle&&) = delete;
DatabaseConnectionHandle& operator=(DatabaseConnectionHandle&&) = delete;
/// Allow access to the database class itself
/// This pointer must *never* stored in a variable as it's lifetime is tied to the lifetime
/// of this class.
MYSQL* db() noexcept;
private:
DatabaseConnectionPoolPtr m_dcp;
int m_id;
MYSQL* m_db = nullptr;
};
#endif // DATABASECONNECTIONMANAGER_H
|