mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-27 14:52:56 +00:00
refactor: 重构基础模型和响应类,增加success字段 fix: 修复定时任务日志记录和异常处理问题 style: 调整中间件日志记录逻辑,优化参数处理 docs: 更新数据库配置和依赖项说明 perf: 优化文件上传服务,支持OSS存储 test: 添加定时任务日志模型和参数验证 chore: 更新依赖项,添加openai库支持
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import json
|
||
|
||
from fastapi.encoders import jsonable_encoder
|
||
from sqlalchemy import select
|
||
from config.database import Base
|
||
from config.get_db import get_db
|
||
import logging
|
||
|
||
from module_admin.entity.do.car_driver_do import CarDriver
|
||
from module_admin.entity.do.student_info_do import StudentInfo
|
||
|
||
class TableTool:
|
||
|
||
logger = logging.getLogger(__name__)
|
||
# 因为mcp服务是在另外进程里面,需要导入模型,否则Base.registry.mappers是空的
|
||
support_modules = [CarDriver, StudentInfo]
|
||
|
||
@classmethod
|
||
async def fetch_table_data(cls, table_name: str) -> str:
|
||
async for query_db in get_db():
|
||
for mapper in Base.registry.mappers:
|
||
table_cls = mapper.class_
|
||
if hasattr(table_cls, '__tablename__') and table_cls.__tablename__ == table_name:
|
||
result = await query_db.execute(select(table_cls))
|
||
data = result.scalars().all()
|
||
json_str = json.dumps(jsonable_encoder(data), ensure_ascii=False)
|
||
return json_str
|
||
raise ValueError(f"No model found for table name: {table_name},to check if you have imported it")
|
||
|
||
|