Files
mtusi2026lab2/app/db.py
T
Queenfish 6bfbcf74fc
Skeleton contracts / contracts (pull_request) Failing after 37s
Мессенджер с Postgres, Redis, Valkey
2026-10-08 13:21:48 +03:00

30 lines
697 B
Python

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()