mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor(db): 修复异步连接池无界增长,并完成 SQLAlchemy 2.0 迁移与分层归位 (#6320)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from sqlalchemy import Column, String, JSON, select
|
||||
from typing import Any, Optional
|
||||
from sqlalchemy import String, JSON, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm import Mapped, Session, mapped_column
|
||||
|
||||
from app.db import db_query, db_update, Base, async_db_query, get_id_column
|
||||
|
||||
@@ -11,14 +12,14 @@ class SystemConfig(Base):
|
||||
"""
|
||||
id = get_id_column()
|
||||
# 主键
|
||||
key = Column(String, index=True)
|
||||
key: Mapped[Optional[str]] = mapped_column(String, index=True)
|
||||
# 值
|
||||
value = Column(JSON)
|
||||
value: Mapped[Optional[Any]] = mapped_column(JSON)
|
||||
|
||||
@classmethod
|
||||
@db_query
|
||||
def get_by_key(cls, db: Session, key: str):
|
||||
return db.query(cls).filter(cls.key == key).first()
|
||||
return db.execute(select(cls).where(cls.key == key)).scalars().first()
|
||||
|
||||
@classmethod
|
||||
@async_db_query
|
||||
|
||||
Reference in New Issue
Block a user