2.5 KiB
2.5 KiB
后端需求 - 表结构返回 columns 数据
问题描述
前端在 Edit Mapping 页面需要展示表的列信息(字段名、类型、COMMENT等),但前端自行解析 DDL 存在困难。
需求
后端在获取表结构列表时,需要同时返回:
- DDL 语句(已有的需求,继续保留)
- 结构化的 columns 数据(新增)
返回数据结构
{
"success": true,
"tables": [
{
"table_name": "exam_scores",
"table_comment": "考试成绩表",
"ddl": "CREATE TABLE `exam_scores` (...)",
"columns": [
{
"column_name": "id",
"data_type": "int",
"column_type": "int(10) unsigned",
"is_nullable": "NO",
"default_value": null,
"column_key": "PRI",
"extra": "auto_increment",
"column_comment": ""
},
{
"column_name": "student_id",
"data_type": "int",
"column_type": "int(10) unsigned",
"is_nullable": "NO",
"default_value": null,
"column_key": "",
"extra": "",
"column_comment": ""
},
{
"column_name": "subject",
"data_type": "varchar",
"column_type": "varchar(50)",
"is_nullable": "NO",
"default_value": null,
"column_key": "",
"extra": "",
"column_comment": "科目"
},
{
"column_name": "score",
"data_type": "double",
"column_type": "double",
"is_nullable": "YES",
"default_value": null,
"column_key": "",
"extra": "",
"column_comment": "分数"
}
]
}
]
}
字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| column_name | string | 列名 |
| data_type | string | 数据类型(如 int, varchar, double) |
| column_type | string | 完整列类型(如 int(10) unsigned) |
| is_nullable | string | 是否可空(YES/NO) |
| default_value | string | 默认值 |
| column_key | string | 主键标识(PRI/MUL/UNI) |
| extra | string | 额外信息(如 auto_increment) |
| column_comment | string | 列注释 |
影响范围
- 文件:
server/internal/service/database_service.go - 函数:
getMySQLTables,getPostgresTables - 数据模型:
server/internal/model/sub_table_info.go的ColumnInfo结构体
优先级
高 - 前端 Edit Mapping 页面字段映射功能依赖此数据