mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-30 20:54:32 +08:00
78 lines
2.4 KiB
Python
78 lines
2.4 KiB
Python
from typing import Any, Optional
|
|
from sqlalchemy import String, JSON, Index, delete, select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy.orm import Mapped, Session, mapped_column
|
|
|
|
from app.db import (
|
|
db_query,
|
|
db_update,
|
|
async_db_query,
|
|
get_id_column,
|
|
Base,
|
|
)
|
|
|
|
|
|
class PluginData(Base):
|
|
"""
|
|
插件数据表
|
|
"""
|
|
id = get_id_column()
|
|
plugin_id: Mapped[str] = mapped_column(String, nullable=False)
|
|
key: Mapped[str] = mapped_column(String, nullable=False)
|
|
value: Mapped[Optional[Any]] = mapped_column(JSON)
|
|
|
|
__table_args__ = (
|
|
Index('ix_plugindata_plugin_id_key', 'plugin_id', 'key'),
|
|
)
|
|
|
|
@classmethod
|
|
@db_query
|
|
def get_plugin_data(cls, db: Session, plugin_id: str):
|
|
return list(db.execute(select(cls).where(cls.plugin_id == plugin_id)).scalars().all())
|
|
|
|
@classmethod
|
|
@async_db_query
|
|
async def async_get_plugin_data(cls, db: AsyncSession, plugin_id: str):
|
|
result = await db.execute(select(cls).where(cls.plugin_id == plugin_id))
|
|
return list(result.scalars().all())
|
|
|
|
@classmethod
|
|
@db_query
|
|
def get_plugin_data_by_key(cls, db: Session, plugin_id: str, key: str):
|
|
return db.execute(
|
|
select(cls).where(cls.plugin_id == plugin_id, cls.key == key)
|
|
).scalars().first()
|
|
|
|
@classmethod
|
|
@async_db_query
|
|
async def async_get_plugin_data_by_key(
|
|
cls, db: AsyncSession, plugin_id: str, key: str
|
|
):
|
|
result = await db.execute(
|
|
select(cls).where(cls.plugin_id == plugin_id, cls.key == key)
|
|
)
|
|
return result.scalar_one_or_none()
|
|
|
|
@classmethod
|
|
@db_update
|
|
def del_plugin_data_by_key(cls, db: Session, plugin_id: str, key: str):
|
|
db.execute(delete(cls).where(cls.plugin_id == plugin_id, cls.key == key))
|
|
|
|
@classmethod
|
|
@db_update
|
|
def del_plugin_data(cls, db: Session, plugin_id: str):
|
|
db.execute(delete(cls).where(cls.plugin_id == plugin_id))
|
|
|
|
@classmethod
|
|
@db_query
|
|
def get_plugin_data_by_plugin_id(cls, db: Session, plugin_id: str):
|
|
return list(db.execute(select(cls).where(cls.plugin_id == plugin_id)).scalars().all())
|
|
|
|
@classmethod
|
|
@async_db_query
|
|
async def async_get_plugin_data_by_plugin_id(
|
|
cls, db: AsyncSession, plugin_id: str
|
|
):
|
|
result = await db.execute(select(cls).where(cls.plugin_id == plugin_id))
|
|
return list(result.scalars().all())
|