删除旧文件;更新数据库查询方法
This commit is contained in:
35
postgresql/scada_info.py
Normal file
35
postgresql/scada_info.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from typing import List, Optional, Any
|
||||
from psycopg import AsyncConnection
|
||||
|
||||
|
||||
class ScadaRepository:
|
||||
|
||||
@staticmethod
|
||||
async def get_scadas_info(conn: AsyncConnection) -> List[dict]:
|
||||
"""
|
||||
查询pg数据库中,scada_info 的所有记录
|
||||
:param conn: 异步数据库连接
|
||||
:return: 包含所有记录的列表,每条记录为一个字典
|
||||
"""
|
||||
async with conn.cursor() as cur:
|
||||
await cur.execute(
|
||||
"""
|
||||
SELECT id, type, transmission_mode, transmission_frequency, reliability
|
||||
FROM public.scada_info
|
||||
"""
|
||||
)
|
||||
records = await cur.fetchall()
|
||||
|
||||
# 将查询结果转换为字典列表
|
||||
records_list = []
|
||||
for record in records:
|
||||
record_dict = {
|
||||
"id": record[0],
|
||||
"type": record[1],
|
||||
"transmission_mode": record[2],
|
||||
"transmission_frequency": record[3],
|
||||
"reliability": record[4],
|
||||
}
|
||||
records_list.append(record_dict)
|
||||
|
||||
return records_list
|
||||
Reference in New Issue
Block a user