mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 07:27:15 +08:00
refactor: make model sessions explicit
This commit is contained in:
@@ -4,7 +4,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import Mapped, Session, mapped_column
|
||||
|
||||
from app.db.base import Base, get_id_column
|
||||
from app.db.decorators import legacy_async_db_query, legacy_db_query
|
||||
|
||||
|
||||
class SystemConfig(Base):
|
||||
@@ -18,15 +17,13 @@ class SystemConfig(Base):
|
||||
value: Mapped[Optional[Any]] = mapped_column(JSON)
|
||||
|
||||
@classmethod
|
||||
@legacy_db_query
|
||||
def get_by_key(cls, db: Session, key: str):
|
||||
"""按配置键查询系统配置,并保留旧插件无 Session 调用。"""
|
||||
"""在调用方 Session 中按配置键查询系统配置。"""
|
||||
return db.execute(select(cls).where(cls.key == key)).scalars().first()
|
||||
|
||||
@classmethod
|
||||
@legacy_async_db_query
|
||||
async def async_get_by_key(cls, db: AsyncSession, key: str):
|
||||
"""异步按配置键查询系统配置,并保留旧插件无 Session 调用。"""
|
||||
"""在调用方 AsyncSession 中按配置键查询系统配置。"""
|
||||
result = await db.execute(select(cls).where(cls.key == key))
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user