29 lines
672 B
Python
29 lines
672 B
Python
"""PostgreSQL 连接池管理"""
|
|
|
|
import asyncpg
|
|
import os
|
|
|
|
DB_CONFIG = {
|
|
"host": os.getenv("ERP_DB_HOST", "192.168.1.206"),
|
|
"port": int(os.getenv("ERP_DB_PORT", "5432")),
|
|
"user": os.getenv("ERP_DB_USER", "postgres"),
|
|
"password": os.getenv("ERP_DB_PASSWORD", "digiwin"),
|
|
"database": os.getenv("ERP_DB_NAME", "smart_quotation_auto"),
|
|
}
|
|
|
|
_pool: asyncpg.Pool | None = None
|
|
|
|
|
|
async def get_pool() -> asyncpg.Pool:
|
|
global _pool
|
|
if _pool is None:
|
|
_pool = await asyncpg.create_pool(**DB_CONFIG, min_size=2, max_size=10)
|
|
return _pool
|
|
|
|
|
|
async def close_pool():
|
|
global _pool
|
|
if _pool:
|
|
await _pool.close()
|
|
_pool = None
|