fix(db): 适配 SQLAlchemy 2.0 API 变更
更新了与数据库交互的代码,以适配 SQLAlchemy 2.0 引入的 API 变更,解决相关的废弃警告和异步调用问题。 主要变更包括: - 使用 `scalars().first()` 替代已废弃的 `scalar()` 方法。 - 在获取所有标量结果时显式调用 `.all()`。 - 对异步引擎 `get_engine()` 的调用进行 `await`。 - 移除了向 Inspector 方法(如 `get_table_names`)传递多余的 `conn` 参数。
This commit is contained in:
committed by
Windpicker-owo
parent
83eb5c80c5
commit
ba91b99674
@@ -249,7 +249,7 @@ class ChatManager:
|
||||
# 检查数据库中是否存在
|
||||
async def _db_find_stream_async(s_id: str):
|
||||
async with get_db_session() as session:
|
||||
return (await session.execute(select(ChatStreams).where(ChatStreams.stream_id == s_id))).scalar()
|
||||
return (await session.execute(select(ChatStreams).where(ChatStreams.stream_id == s_id))).scalars().first()
|
||||
|
||||
model_instance = await _db_find_stream_async(stream_id)
|
||||
|
||||
@@ -396,7 +396,7 @@ class ChatManager:
|
||||
async def _db_load_all_streams_async():
|
||||
loaded_streams_data = []
|
||||
async with get_db_session() as session:
|
||||
for model_instance in (await session.execute(select(ChatStreams))).scalars():
|
||||
for model_instance in (await session.execute(select(ChatStreams))).scalars().all():
|
||||
user_info_data = {
|
||||
"platform": model_instance.user_platform,
|
||||
"user_id": model_instance.user_id,
|
||||
|
||||
Reference in New Issue
Block a user