重构时序数据库连接逻辑,移除冗余代码

This commit is contained in:
2026-03-13 16:18:11 +08:00
parent c137adedad
commit 1673396e1a
5 changed files with 50 additions and 53 deletions
+5 -5
View File
@@ -3,7 +3,7 @@ from contextlib import asynccontextmanager
from typing import AsyncGenerator, Dict, Optional
import psycopg_pool
from psycopg.rows import dict_row
import app.infra.db.timescaledb.timescaledb_info as timescaledb_info
from app.core.config import get_timescaledb_pgconn_string
# Configure logging
logger = logging.getLogger(__name__)
@@ -21,9 +21,9 @@ class Database:
# Get connection string, handling default case where target_db_name might be None
if target_db_name:
conn_string = timescaledb_info.get_pgconn_string(db_name=target_db_name)
conn_string = get_timescaledb_pgconn_string(db_name=target_db_name)
else:
conn_string = timescaledb_info.get_pgconn_string()
conn_string = get_timescaledb_pgconn_string()
try:
self.pool = psycopg_pool.AsyncConnectionPool(
@@ -54,8 +54,8 @@ class Database:
"""Get the TimescaleDB connection string."""
target_db_name = db_name or self.db_name
if target_db_name:
return timescaledb_info.get_pgconn_string(db_name=target_db_name)
return timescaledb_info.get_pgconn_string()
return get_timescaledb_pgconn_string(db_name=target_db_name)
return get_timescaledb_pgconn_string()
@asynccontextmanager
async def get_connection(self) -> AsyncGenerator: