| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- """PostgreSQL 异步后端 —— 基于 asyncpg 连接池
- 状态:未实现。init() 会抛出 NotImplementedError。
- """
- import logging
- from typing import Any, Optional
- from supply.infra.database.ports import SqlBackend
- logger = logging.getLogger(__name__)
- class PgBackend(SqlBackend):
- """PostgreSQL 异步连接池后端"""
- def __init__(self, name: str, config: Any):
- super().__init__(name, config)
- self._pool = None
- # ==================== 生命周期 ====================
- async def init(self) -> None:
- raise NotImplementedError(
- "PgBackend 尚未实现。需要安装 asyncpg 并完成连接池初始化逻辑。"
- )
- async def close(self) -> None:
- if self._pool is not None:
- self._pool = None
- self._initialized = False
- async def health(self) -> bool:
- return False
- # ==================== SQL 操作 ====================
- async def fetch(
- self,
- query: str,
- params: Optional[tuple] = None,
- ) -> list[dict]:
- raise NotImplementedError("PgBackend 尚未实现")
- async def fetch_one(
- self,
- query: str,
- params: Optional[tuple] = None,
- ) -> Optional[dict]:
- raise NotImplementedError("PgBackend 尚未实现")
- async def execute(
- self,
- query: str,
- params: Any = None,
- *,
- batch: bool = False,
- ) -> int:
- raise NotImplementedError("PgBackend 尚未实现")
|