20 lines
432 B
Python
20 lines
432 B
Python
"""Sdílené FastAPI závislosti (DB pool)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncpg
|
|
from fastapi import HTTPException
|
|
|
|
_pg_pool: asyncpg.Pool | None = None
|
|
|
|
|
|
def set_pg_pool(pool: asyncpg.Pool | None) -> None:
|
|
global _pg_pool
|
|
_pg_pool = pool
|
|
|
|
|
|
async def get_pg_pool() -> asyncpg.Pool:
|
|
if _pg_pool is None:
|
|
raise HTTPException(status_code=503, detail="Database pool not ready")
|
|
return _pg_pool
|