diff --git a/app/services/database.py b/app/services/database.py index 6e1afc8..8585d4d 100644 --- a/app/services/database.py +++ b/app/services/database.py @@ -187,16 +187,36 @@ class DatabaseService: } @staticmethod - def get_table_list() -> List[str]: - """获取所有表名""" + def get_table_list() -> Dict[str, Any]: + """获取所有表名及字段信息""" try: inspector = inspect(engine) # 排除mysql的系统表和accounts表 - data = [table for table in inspector.get_table_names() if not table.startswith('mysql') and table != 'accounts' and table != 'apscheduler_jobs'] + table_names = [table for table in inspector.get_table_names() + if not table.startswith('mysql') and table != 'accounts' and table != 'apscheduler_jobs'] + + tables_info = [] + for table_name in table_names: + # 获取表的列信息 + columns = inspector.get_columns(table_name) + column_info = [] + for column in columns: + column_info.append({ + "name": column['name'], + "type": str(column['type']), + "nullable": column['nullable'], + "default": column['default'] + }) + + tables_info.append({ + "table_name": table_name, + "columns": column_info + }) + return { "success": True, - "message": "获取表名成功", - "data": data + "message": "获取表名及字段信息成功", + "data": tables_info } except Exception as e: return {