"""sys_config 仓储:运营参数读写(示例+可复用模板)。""" from __future__ import annotations from sqlalchemy import select from model.sys_config import SysConfig from repositories.base import BaseRepository class SysConfigRepo(BaseRepository): model = SysConfig async def get_value(self, key: str, default: str | None = None) -> str | None: row = await self.db.scalar(select(SysConfig).where(SysConfig.config_key == key)) return row.config_value if row else default async def set_value(self, key: str, value: str, description: str | None = None) -> SysConfig: row = await self.db.scalar(select(SysConfig).where(SysConfig.config_key == key)) if row is None: row = SysConfig(config_key=key, config_value=value, description=description) self.db.add(row) else: row.config_value = value if description: row.description = description await self.db.commit() await self.db.refresh(row) return row