mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-11 03:18:29 +08:00
🐛 config 中添加 clear_db 方法,用于清空数据库内容;添加clear_db fixture,用于在单测前后清空数据库
This commit is contained in:
@@ -363,5 +363,16 @@ class DBConfig:
|
||||
res.sort(key=lambda x: (x.target.platform_name, x.cookie_id, x.target_id))
|
||||
return res
|
||||
|
||||
async def clear_db(self):
|
||||
"""清空数据库"""
|
||||
async with create_session() as sess:
|
||||
await sess.execute(delete(User))
|
||||
await sess.execute(delete(Target))
|
||||
await sess.execute(delete(ScheduleTimeWeight))
|
||||
await sess.execute(delete(Subscribe))
|
||||
await sess.execute(delete(Cookie))
|
||||
await sess.execute(delete(CookieTarget))
|
||||
await sess.commit()
|
||||
|
||||
|
||||
config = DBConfig()
|
||||
|
||||
Reference in New Issue
Block a user