Files
X-Agents/server/internal/model/sub_table_info.go
DESKTOP-72TV0V4\caoxiaozhu b2bc9988a9 feat: 重构前后端架构,添加Go后端和Python Agent服务
- 新增 Go 语言后端服务(server/),包含用户认证、Agent管理、数据库连接等API
- 新增 Python Agent 服务(agent/),实现Agent核心逻辑和工具集
- 前端从原生HTML迁移到Vue.js框架(web/src/)
- 添加 Docker Compose 支持(docker-compose.yml)
- 添加项目架构文档(docs/ARCHITECTURE.md)
- 添加环境变量示例(.env.example)和本地启动脚本(start-local.ps1)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 16:39:42 +08:00

118 lines
4.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import (
"encoding/json"
"time"
)
// TableDDLInfo 表结构信息
type TableDDLInfo struct {
TableName string `json:"table_name"` // 表名
TableComment string `json:"table_comment"` // 表注释
Columns []ColumnInfo `json:"columns"` // 列信息
DDL string `json:"ddl"` // 建表DDL
Indexes []IndexInfo `json:"indexes"` // 索引信息
}
// ColumnInfo 列信息
type ColumnInfo struct {
ColumnName string `json:"column_name"` // 列名
DataType string `json:"data_type"` // 数据类型
ColumnType string `json:"column_type"` // 列类型(含长度)
IsNullable string `json:"is_nullable"` // 是否可空
DefaultValue string `json:"default_value"` // 默认值
ColumnKey string `json:"column_key"` // 主键/索引
Extra string `json:"extra"` // 自增等
ColumnComment string `json:"column_comment"` // 列注释
MappedName string `json:"mapped_name"` // 字段中文映射名
}
// IndexInfo 索引信息
type IndexInfo struct {
IndexName string `json:"index_name"` // 索引名
ColumnName string `json:"column_name"` // 列名
NonUnique int `json:"non_unique"` // 是否唯一
IndexType string `json:"index_type"` // 索引类型
}
// SubTableInfo 子表信息
type SubTableInfo struct {
ID string `json:"id"` // UUID
DatabaseID string `json:"database_id"` // 关联的数据库ID
ParentTable string `json:"parent_table"` // 父表名
SubTableName string `json:"sub_table_name"` // 子表名
SubTableComment string `json:"sub_table_comment"` // 子表注释
MappingType string `json:"mapping_type" gorm:"type:varchar(20)"` // 映射类型
RelationField string `json:"relation_field" gorm:"type:varchar(100)"` // 关联字段
RelationType string `json:"relation_type" gorm:"type:varchar(20)"` // 关联类型
Fields string `json:"-" gorm:"type:longtext"` // 字段映射列表JSON 格式,内部存储)
FieldsList []FieldMapping `json:"fields" gorm:"-"` // 字段映射列表(返回给前端)
DDL string `json:"ddl" gorm:"type:longtext"` // 建表 DDL
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// FieldMapping 字段映射
type FieldMapping struct {
ColumnName string `json:"column_name"` // 列名
MappedName string `json:"mapped_name"` // 中文映射名
}
// GetFields 获取字段映射列表
func (s *SubTableInfo) GetFields() []FieldMapping {
if s.Fields == "" {
return nil
}
var fields []FieldMapping
if err := json.Unmarshal([]byte(s.Fields), &fields); err != nil {
return nil
}
return fields
}
// SetFields 设置字段映射列表
func (s *SubTableInfo) SetFields(fields []FieldMapping) {
if len(fields) == 0 {
s.Fields = ""
return
}
data, _ := json.Marshal(fields)
s.Fields = string(data)
}
// TableName 表名
func (SubTableInfo) TableName() string {
return "sub_table_info"
}
// CreateSubTableRequest 创建子表请求
type CreateSubTableRequest struct {
DatabaseID string `json:"database_id" binding:"required"`
ParentTable string `json:"parent_table" binding:"required"`
SubTableName string `json:"sub_table_name" binding:"required"`
SubTableComment string `json:"sub_table_comment"`
MappingType string `json:"mapping_type"`
RelationField string `json:"relation_field"`
RelationType string `json:"relation_type"`
Fields []FieldMapping `json:"fields"` // 字段映射列表
}
// UpdateSubTableRequest 更新子表请求
type UpdateSubTableRequest struct {
ParentTable string `json:"parent_table"`
SubTableName string `json:"sub_table_name"`
SubTableComment string `json:"sub_table_comment"`
MappingType string `json:"mapping_type"`
RelationField string `json:"relation_field"`
RelationType string `json:"relation_type"`
}
// SubTableMapping 完整的子表映射配置(存储到文件的格式)
type SubTableMapping struct {
DatabaseID string `json:"database_id"`
DatabaseName string `json:"database_name"`
DBType string `json:"db_type"`
Tables []SubTableInfo `json:"tables"`
UpdatedAt time.Time `json:"updated_at"`
}