Files
RoleForge/app/db/pool.py
Sergey Antropoff 1d2301fb09 first commit
2026-04-30 08:59:31 +03:00

27 lines
564 B
Python

import asyncpg
from app.core.config import get_settings
pool: asyncpg.Pool | None = None
async def init_pool() -> asyncpg.Pool:
global pool
if pool is None:
settings = get_settings()
pool = await asyncpg.create_pool(settings.database_dsn, min_size=2, max_size=20)
return pool
async def close_pool() -> None:
global pool
if pool is not None:
await pool.close()
pool = None
def get_pool() -> asyncpg.Pool:
if pool is None:
raise RuntimeError("Database pool is not initialized")
return pool