import asyncpg from app.config import config class Database: def __init__(self) -> None: self._pool: asyncpg.Pool | None = None async def connect(self) -> None: self._pool = await asyncpg.create_pool( config.DATABASE_URL, min_size=1, max_size=10, command_timeout=5, timeout=5, ) async def close(self) -> None: if self._pool is not None: await self._pool.close() self._pool = None @property def pool(self) -> asyncpg.Pool: if self._pool is None: raise RuntimeError("database is not connected") return self._pool db = Database()