""" database.py — Async PostgreSQL connection pool (asyncpg). """ from __future__ import annotations import asyncpg from core.settings import Settings _pool: asyncpg.Pool | None = None async def create_pool(settings: Settings) -> asyncpg.Pool: global _pool _pool = await asyncpg.create_pool( settings.database_url, min_size=settings.db_pool_min, max_size=settings.db_pool_max, command_timeout=60, ) return _pool async def get_pool() -> asyncpg.Pool: if _pool is None: raise RuntimeError('Database pool not initialised') return _pool async def close_pool() -> None: global _pool if _pool: await _pool.close() _pool = None