From 66b009f9a354b77f6c07ea709aab88988c74d5a5 Mon Sep 17 00:00:00 2001 From: lhx Date: Sat, 27 Sep 2025 09:38:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/database.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) 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 {