获取表接口
This commit is contained in:
@@ -187,16 +187,36 @@ class DatabaseService:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_table_list() -> List[str]:
|
def get_table_list() -> Dict[str, Any]:
|
||||||
"""获取所有表名"""
|
"""获取所有表名及字段信息"""
|
||||||
try:
|
try:
|
||||||
inspector = inspect(engine)
|
inspector = inspect(engine)
|
||||||
# 排除mysql的系统表和accounts表
|
# 排除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 {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": "获取表名成功",
|
"message": "获取表名及字段信息成功",
|
||||||
"data": data
|
"data": tables_info
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user