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

@@ -9,7 +9,7 @@ type DatabaseInfo struct {
ID string `json:"id" gorm:"primaryKey;size:36"` // UUID
Name string `json:"name" gorm:"size:100;not null"` // 数据库名称
Description string `json:"description" gorm:"size:500"` // 描述
DBType string `json:"db_type" gorm:"size:20;not null"` // 数据库类型: mysql, postgres, mongodb等
DBType string `json:"db_type" gorm:"size:20;not null"` // 数据库类型: mysql, postgres, mongodb, neo4j
Host string `json:"host" gorm:"size:255;not null"` // 主机地址
Port int `json:"port" gorm:"not null"` // 端口
Username string `json:"username" gorm:"size:100;not null"` // 用户名
@@ -17,6 +17,12 @@ type DatabaseInfo struct {
Database string `json:"database" gorm:"size:100"` // 数据库名
TableCount int `json:"table_count" gorm:"default:0"` // 子表数量
// Neo4j 专用字段
URI string `json:"uri" gorm:"size:255"` // Neo4j 连接地址 (bolt://host:7687)
GraphLabels string `json:"graph_labels" gorm:"size:1000"` // Neo4j 标签列表 (JSON 格式)
GraphRelationship string `json:"graph_relationship" gorm:"size:1000"` // Neo4j 关系类型列表 (JSON 格式)
SelectedLabel string `json:"selected_label" gorm:"size:100"` // 当前选中的标签
// 连接选项
Charset string `json:"charset" gorm:"size:20;default:utf8mb4"` // 字符集
SSLMode string `json:"ssl_mode" gorm:"size:20"` // SSL模式
@@ -48,17 +54,38 @@ type CreateDatabaseRequest struct {
// UpdateRequest 更新数据库信息请求
type UpdateDatabaseRequest struct {
Name string `json:"name"`
Description string `json:"description"`
DBType string `json:"db_type"`
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
TableCount int `json:"table_count"`
Charset string `json:"charset"`
SSLMode string `json:"ssl_mode"`
Name string `json:"name"`
Description string `json:"description"`
DBType string `json:"db_type"`
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
TableCount int `json:"table_count"`
Charset string `json:"charset"`
SSLMode string `json:"ssl_mode"`
URI string `json:"uri"` // Neo4j 连接地址
GraphLabels string `json:"graph_labels"` // Neo4j 标签列表 (JSON)
GraphRelationship string `json:"graph_relationship"` // Neo4j 关系类型列表 (JSON)
SelectedLabel string `json:"selected_label"` // 当前选中的标签
}
// SaveGraphRequest 保存图谱信息请求
type SaveGraphRequest struct {
DatabaseID string `json:"databaseId" binding:"required"`
DatabaseName string `json:"databaseName" binding:"required"`
URI string `json:"uri" binding:"required"`
Username string `json:"username" binding:"required"`
Labels []string `json:"labels" binding:"required"`
RelationshipTypes []string `json:"relationshipTypes" binding:"required"`
SelectedLabel string `json:"selectedLabel"`
}
// SaveGraphResponse 保存图谱信息响应
type SaveGraphResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
}
// CheckRequest 检查连接请求
@@ -72,12 +99,97 @@ type CheckRequest struct {
Charset string `json:"charset"`
SSLMode string `json:"ssl_mode"`
DatabaseID string `json:"database_id"` // 可选,用于获取已保存的字段映射
URI string `json:"uri"` // Neo4j 连接地址,如 bolt://localhost:7687
}
// CheckResponse 检查连接响应
type CheckResponse struct {
Success bool `json:"success"` // 是否连接成功
Message string `json:"message"` // 消息
Tables []TableDDLInfo `json:"tables,omitempty"` // 表列表(连接成功时返回
Database string `json:"database"` // 数据库名
Success bool `json:"success"` // 是否连接成功
Message string `json:"message"` // 消息
Tables []TableDDLInfo `json:"tables,omitempty"` // 表列表(关系型数据库
Database string `json:"database"` // 数据库名
Graphs *GraphOverview `json:"graphs,omitempty"` // 图谱概览Neo4j
}
// GraphOverview 图谱概览数据
type GraphOverview struct {
Labels []LabelCount `json:"labels"` // 标签列表
RelationshipTypes []RelTypeCount `json:"relationshipTypes"` // 关系类型列表
Nodes []NodeProperty `json:"nodes"` // 节点属性定义
Relationships []RelProperty `json:"relationships"` // 关系属性定义
}
// LabelCount 标签数量统计
type LabelCount struct {
Name string `json:"name"` // 标签名
Count int `json:"count"` // 节点数量
}
// RelTypeCount 关系类型数量统计
type RelTypeCount struct {
Name string `json:"name"` // 关系类型名
Count int `json:"count"` // 关系数量
}
// NodeProperty 节点属性定义
type NodeProperty struct {
Label string `json:"label"` // 节点标签名
Properties []PropertyInfo `json:"properties"` // 属性列表
}
// PropertyInfo 属性信息
type PropertyInfo struct {
Name string `json:"name"` // 属性名
Type string `json:"type"` // 属性类型
}
// RelProperty 关系属性定义
type RelProperty struct {
Type string `json:"type"` // 关系类型名
StartLabel string `json:"startLabel"` // 起始节点标签
EndLabel string `json:"endLabel"` // 目标节点标签
Properties []PropertyInfo `json:"properties"` // 属性列表
}
// Neo4jNodeRequest 获取节点详情请求
type Neo4jNodeRequest struct {
URI string `json:"uri" binding:"required"`
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
Database string `json:"database"`
Label string `json:"label" binding:"required"`
Limit int `json:"limit"` // 默认 10
}
// Neo4jNodeResponse 获取节点详情响应
type Neo4jNodeResponse struct {
Success bool `json:"success"` // 是否成功
Message string `json:"message"` // 消息
Nodes []map[string]interface{} `json:"nodes"` // 节点数据
Properties []PropertyInfo `json:"properties"` // 属性定义列表
}
// Neo4jRelRequest 获取关系详情请求
type Neo4jRelRequest struct {
URI string `json:"uri" binding:"required"`
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
Database string `json:"database"`
RelationshipType string `json:"relationship_type" binding:"required"`
Limit int `json:"limit"` // 默认 10
}
// Neo4jRelResponse 获取关系详情响应
type Neo4jRelResponse struct {
Success bool `json:"success"` // 是否成功
Message string `json:"message"` // 消息
Relationships []Neo4jRelationship `json:"relationships"` // 关系数据
}
// Neo4jRelationship 关系数据
type Neo4jRelationship struct {
ID string `json:"id"` // 关系唯一标识
Source string `json:"source"` // 起始节点ID
Target string `json:"target"` // 目标节点ID
Properties map[string]interface{} `json:"properties"` // 关系属性
}