Files
X-Agents/server/internal/model/database_info.go

197 lines
8.7 KiB
Go
Raw Normal View History

package model
import (
"time"
)
// DatabaseInfo 数据库连接信息
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, 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"` // 用户名
Password string `json:"password" gorm:"size:255"` // 密码(建议加密存储)
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模式
// 时间
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 表名
func (DatabaseInfo) TableName() string {
return "database_info"
}
// CreateRequest 创建数据库信息请求(支持同时保存子表配置)
type CreateDatabaseRequest struct {
Name string `json:"name" binding:"required"`
Description string `json:"description"`
DBType string `json:"db_type" binding:"required"`
Host string `json:"host" binding:"required"`
Port int `json:"port" binding:"required"`
Username string `json:"username" binding:"required"`
Password string `json:"password"`
Database string `json:"database"`
Charset string `json:"charset"`
SSLMode string `json:"ssl_mode"`
SubTables []CreateSubTableRequest `json:"sub_tables"` // 可选,子表配置
}
// 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"`
URI string `json:"uri"` // Neo4j 连接地址
GraphLabels string `json:"graph_labels"` // Neo4j 标签列表 (JSON)
GraphRelationship string `json:"graph_relationship"` // Neo4j 关系类型列表 (JSON)
SelectedLabel string `json:"selected_label"` // 当前选中的标签
SubTables []CreateSubTableRequest `json:"sub_tables"` // 子表配置
}
// 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 检查连接请求
type CheckRequest struct {
DBType string `json:"db_type" binding:"required"`
Host string `json:"host" binding:"required"`
Port int `json:"port" binding:"required"`
Username string `json:"username" binding:"required"`
Password string `json:"password"`
Database string `json:"database"`
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"` // 数据库名
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"` // 关系属性
}