🎨 update_data_by_uid()允许bot_id传入None

This commit is contained in:
KimigaiiWuyi 2024-10-12 07:24:38 +08:00
parent 81eda3a2c3
commit 4b4379ae4a
2 changed files with 12 additions and 8 deletions

View File

@ -334,7 +334,7 @@ class BaseBotIDModel(BaseIDModel):
cls,
session: AsyncSession,
uid: str,
bot_id: str,
bot_id: Optional[str] = None,
game_name: Optional[str] = None,
**data,
) -> int:
@ -369,9 +369,11 @@ class BaseBotIDModel(BaseIDModel):
data[uid_name] = uid
return await cls.full_insert_data(bot_id=bot_id, **data)
sql = update(cls).where(
and_(getattr(cls, uid_name) == uid, cls.bot_id == bot_id)
)
sql = update(cls).where(and_(getattr(cls, uid_name) == uid))
if bot_id is not None:
sql = sql.where(cls.bot_id == bot_id)
if data is not None:
query = sql.values(**data)
query.execution_options(synchronize_session='fetch')

View File

@ -11,7 +11,7 @@ async def set_database_value(
command_start: str,
command_value: str,
uid: str,
bot_id: str,
bot_id: Optional[str],
value: str,
):
fields = model.__fields__
@ -36,7 +36,7 @@ async def set_database_value(
title = title if title else keyname
if desc:
if desc == f'{command_start}{command_value}':
await model.update_data_by_uid(
retcode = await model.update_data_by_uid(
uid,
bot_id,
game_name,
@ -44,5 +44,7 @@ async def set_database_value(
f'{keyname}': value,
},
)
return f'{title}\n📝已设置为{value}'
if retcode == 0:
return f'{title}\n📝已设置为{value}'
else:
return f'{title}\n📝设置失败'