🔧 修复部分数据库读写的代码错误

This commit is contained in:
洛水居室 2022-08-05 21:21:28 +08:00
parent 72b73be299
commit 3601ccdb4c
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
2 changed files with 7 additions and 7 deletions

View File

@ -31,21 +31,21 @@ class CookiesRepository:
if region == RegionEnum.HYPERION: if region == RegionEnum.HYPERION:
statement = select(HyperionCookie).where(HyperionCookie.user_id == user_id) statement = select(HyperionCookie).where(HyperionCookie.user_id == user_id)
results = await session.exec(statement) results = await session.exec(statement)
db_cookies = results.one() db_cookies = results.one()[0]
if db_cookies is None: if db_cookies is None:
raise CookiesNotFoundError(user_id) raise CookiesNotFoundError(user_id)
db_cookies.cookie = cookies db_cookies.cookies = cookies
await session.add(db_cookies) session.add(db_cookies)
await session.commit() await session.commit()
await session.refresh(db_cookies) await session.refresh(db_cookies)
elif region == RegionEnum.HOYOLAB: elif region == RegionEnum.HOYOLAB:
statement = select(HyperionCookie).where(HyperionCookie.user_id == user_id) statement = select(HyperionCookie).where(HyperionCookie.user_id == user_id)
results = await session.add(statement) results = await session.add(statement)
db_cookies = results.one() db_cookies = results.one()[0]
if db_cookies is None: if db_cookies is None:
raise CookiesNotFoundError(user_id) raise CookiesNotFoundError(user_id)
db_cookies.cookie = cookies db_cookies.cookie = cookies
await session.add(db_cookies) session.add(db_cookies)
await session.commit() await session.commit()
await session.refresh(db_cookies) await session.refresh(db_cookies)
else: else:

View File

@ -18,12 +18,12 @@ class UserRepository:
statement = select(User).where(User.user_id == user_id) statement = select(User).where(User.user_id == user_id)
results = await session.exec(statement) results = await session.exec(statement)
user = results.first() user = results.first()
return user return user[0]
async def update_user(self, user: User): async def update_user(self, user: User):
async with self.mysql.Session() as session: async with self.mysql.Session() as session:
session = cast(AsyncSession, session) session = cast(AsyncSession, session)
await session.add(user) session.add(user)
await session.commit() await session.commit()
await session.refresh(user) await session.refresh(user)