You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
721 B

"""
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

Powered by TurnKey Linux.