补全 realtime scheme 中的复合 存储、查询方法
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from psycopg import AsyncConnection
|
||||
|
||||
from .database import get_database_instance
|
||||
from .scada_info import query_pg_scada_info
|
||||
from .scada_info import ScadaRepository
|
||||
|
||||
router = APIRouter(prefix="/postgresql", tags=["postgresql"])
|
||||
|
||||
@@ -26,15 +25,13 @@ async def get_scada_info_with_connection(
|
||||
conn: AsyncConnection = Depends(get_database_connection),
|
||||
):
|
||||
"""
|
||||
使用连接池查询SCADA信息
|
||||
使用连接池查询所有SCADA信息
|
||||
"""
|
||||
try:
|
||||
# 使用连接查询SCADA信息
|
||||
async with conn.cursor() as cur:
|
||||
await cur.execute("SELECT * FROM scada_info")
|
||||
scada_data = await cur.fetchall()
|
||||
# 使用ScadaRepository查询SCADA信息
|
||||
scada_data = await ScadaRepository.get_scadas_info(conn)
|
||||
return {"success": True, "data": scada_data, "count": len(scada_data)}
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"查询SCADA信息时发生错误: {str(e)}"
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user