mirror of
https://github.com/Genshin-bots/gsuid_core.git
synced 2025-06-04 06:29:47 +08:00
🎨 update_data_by_uid()
允许bot_id
传入None
This commit is contained in:
parent
81eda3a2c3
commit
4b4379ae4a
@ -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')
|
||||
|
@ -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📝设置失败'
|
||||
|
Loading…
x
Reference in New Issue
Block a user