feat: 添加Neo4j图数据库支持及前端代码重构

- 新增 Neo4j 图数据库 handler、service、model
- 后端添加 SaveGraph API 接口
- 前端 Database.vue 重构,拆分为独立组件
- 新增 web/src/views/database/ 组件目录
- 删除临时文件 (temp_*.go)
- 添加 Neo4j 相关 API 需求文档

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 09:11:08 +08:00
parent 20015dbd2a
commit c917d6b04c
41 changed files with 4453 additions and 1021 deletions

View File

@@ -10,7 +10,7 @@ POST /database/check
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| db_type | string | 是 | 数据库类型:`mysql``postgres` |
| db_type | string | 是 | 数据库类型:`mysql``postgres``neo4j` |
| host | string | 是 | 数据库主机 |
| port | int | 是 | 数据库端口 |
| username | string | 是 | 用户名 |
@@ -19,8 +19,9 @@ POST /database/check
| charset | string | 否 | 字符集,默认 `utf8mb4` |
| ssl_mode | string | 否 | SSL 模式 |
| database_id | string | 否 | 已存在的数据库ID用于恢复字段映射 |
| uri | string | 否 | Neo4j 连接地址(如 bolt://localhost:7687Neo4j 类型必填 |
## 请求示例
## 请求示例MySQL/PostgreSQL
```json
{
@@ -31,7 +32,19 @@ POST /database/check
"password": "root",
"database": "students",
"charset": "utf8mb4",
"database_id": "xxx-xxx-xxx" // 可选,用于恢复字段映射
"database_id": "xxx-xxx-xxx"
}
```
## 请求示例Neo4j
```json
{
"db_type": "neo4j",
"uri": "bolt://localhost:7687",
"username": "neo4j",
"password": "password",
"database": "neo4j"
}
```
@@ -42,9 +55,10 @@ POST /database/check
| success | bool | 是否连接成功 |
| message | string | 消息 |
| database | string | 数据库名 |
| tables | array | 表结构列表 |
| tables | array | 表结构列表MySQL/PostgreSQL |
| graphs | object | 图谱数据Neo4j |
### tables[] 详情
### tables[] 详情(关系型数据库)
| 参数 | 类型 | 说明 |
|------|------|------|
@@ -67,7 +81,46 @@ POST /database/check
| column_comment | string | 列注释 |
| mapped_name | string | 字段中文映射名(已保存的映射) |
## 返回示例
### graphs 详情Neo4j
| 参数 |类型| 说明 |
|------|------|------|
| labels | array | 标签列表 |
| relationshipTypes | array | 关系类型列表 |
| nodes | array | 节点属性定义 |
| relationships | array | 关系属性定义 |
### graphs.labels[]
| 参数 | 类型 | 说明 |
|------|------|------|
| name | string | 标签名称 |
| count | int | 节点数量 |
### graphs.relationshipTypes[]
| 参数 | 类型 | 说明 |
|------|------|------|
| name | string | 关系类型名称 |
| count | int | 关系数量 |
### graphs.nodes[]
| 参数 | 类型 | 说明 |
|------|------|------|
| label | string | 节点标签名 |
| properties | array | 属性列表 |
### graphs.relationships[]
| 参数 | 类型 | 说明 |
|------|------|------|
| type | string | 关系类型名 |
| startLabel | string | 起始节点标签 |
| endLabel | string | 目标节点标签 |
| properties | array | 属性列表 |
## 返回示例MySQL/PostgreSQL
```json
{
@@ -97,7 +150,51 @@ POST /database/check
}
```
## 返回示例Neo4j
```json
{
"success": true,
"message": "connection successful",
"database": "neo4j",
"graphs": {
"labels": [
{"name": "User", "count": 100},
{"name": "Order", "count": 50}
],
"relationshipTypes": [
{"name": "KNOWS", "count": 30},
{"name": "OWNS", "count": 20}
],
"nodes": [
{
"label": "User",
"properties": [
{"name": "id", "type": "string"},
{"name": "name", "type": "string"}
]
}
],
"relationships": [
{
"type": "KNOWS",
"startLabel": "User",
"endLabel": "User",
"properties": [
{"name": "since", "type": "date"}
]
}
]
}
}
```
## 使用场景
1. **首次连接**:不传 `database_id`,获取实时表结构
2. **恢复映射**:传入 `database_id`,返回已保存的 `mapped_name``ddl`
1. **关系型数据库**
- 首次连接:不传 `database_id`,获取实时表结构
- 恢复映射:传入 `database_id`,返回已保存的 `mapped_name``ddl`
2. **Neo4j 图数据库**
- 连接 Neo4j 并获取图谱概览数据(标签、关系类型、属性定义)
- 用于前端图可视化展示