mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
refactor(db): 修复异步连接池无界增长,并完成 SQLAlchemy 2.0 迁移与分层归位 (#6320)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from sqlalchemy import Column, String, UniqueConstraint, JSON
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Any, Optional
|
||||
from sqlalchemy import String, UniqueConstraint, JSON, select
|
||||
from sqlalchemy.orm import Mapped, Session, mapped_column
|
||||
|
||||
from app.db import db_query, db_update, get_id_column, Base
|
||||
|
||||
@@ -10,11 +11,11 @@ class UserConfig(Base):
|
||||
"""
|
||||
id = get_id_column()
|
||||
# 用户名
|
||||
username = Column(String)
|
||||
username: Mapped[Optional[str]] = mapped_column(String)
|
||||
# 配置键
|
||||
key = Column(String)
|
||||
key: Mapped[Optional[str]] = mapped_column(String)
|
||||
# 值
|
||||
value = Column(JSON)
|
||||
value: Mapped[Optional[Any]] = mapped_column(JSON)
|
||||
|
||||
__table_args__ = (
|
||||
# 用户名和配置键联合唯一
|
||||
@@ -24,10 +25,9 @@ class UserConfig(Base):
|
||||
@classmethod
|
||||
@db_query
|
||||
def get_by_key(cls, db: Session, username: str, key: str):
|
||||
return db.query(cls) \
|
||||
.filter(cls.username == username) \
|
||||
.filter(cls.key == key) \
|
||||
.first()
|
||||
return db.execute(
|
||||
select(cls).where(cls.username == username, cls.key == key)
|
||||
).scalars().first()
|
||||
|
||||
@db_update
|
||||
def delete_by_key(self, db: Session, username: str, key: str):
|
||||
|
||||
Reference in New Issue
Block a user