#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;
};
