fix
This commit is contained in:
24
src/connection_guard.h
Normal file
24
src/connection_guard.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#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;
|
||||
};
|
||||
Reference in New Issue
Block a user