postgresql.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """PostgreSQL 异步后端 —— 基于 asyncpg 连接池
  2. 状态:未实现。init() 会抛出 NotImplementedError。
  3. """
  4. import logging
  5. from typing import Any, Optional
  6. from supply.infra.database.ports import SqlBackend
  7. logger = logging.getLogger(__name__)
  8. class PgBackend(SqlBackend):
  9. """PostgreSQL 异步连接池后端"""
  10. def __init__(self, name: str, config: Any):
  11. super().__init__(name, config)
  12. self._pool = None
  13. # ==================== 生命周期 ====================
  14. async def init(self) -> None:
  15. raise NotImplementedError(
  16. "PgBackend 尚未实现。需要安装 asyncpg 并完成连接池初始化逻辑。"
  17. )
  18. async def close(self) -> None:
  19. if self._pool is not None:
  20. self._pool = None
  21. self._initialized = False
  22. async def health(self) -> bool:
  23. return False
  24. # ==================== SQL 操作 ====================
  25. async def fetch(
  26. self,
  27. query: str,
  28. params: Optional[tuple] = None,
  29. ) -> list[dict]:
  30. raise NotImplementedError("PgBackend 尚未实现")
  31. async def fetch_one(
  32. self,
  33. query: str,
  34. params: Optional[tuple] = None,
  35. ) -> Optional[dict]:
  36. raise NotImplementedError("PgBackend 尚未实现")
  37. async def execute(
  38. self,
  39. query: str,
  40. params: Any = None,
  41. *,
  42. batch: bool = False,
  43. ) -> int:
  44. raise NotImplementedError("PgBackend 尚未实现")