25 lines
448 B
C++
25 lines
448 B
C++
#pragma once
|
|
|
|
#include "connection_pool.h"
|
|
#include <memory>
|
|
|
|
class ConnectionGuard {
|
|
public:
|
|
ConnectionGuard(ConnectionPool &pool)
|
|
: pool(pool), connection(pool.getConnection()) {}
|
|
|
|
~ConnectionGuard() {
|
|
if (connection) {
|
|
pool.releaseConnection(connection);
|
|
}
|
|
}
|
|
|
|
Database &get() {
|
|
return *connection;
|
|
}
|
|
|
|
private:
|
|
ConnectionPool &pool;
|
|
std::shared_ptr<Database> connection;
|
|
};
|