mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-26 02:11:03 +00:00
🔧 修复部分数据库读写的代码错误
This commit is contained in:
parent
72b73be299
commit
3601ccdb4c
@ -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:
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user