功能: - 支持配置 MySQL/MongoDB 可见数据库列表 - 连接删除时自动清理关联数据并关闭连接池 - 新增加载数据库列表 API - 数据库错误提示优化 改进: - 代码简化:消除重复的表单验证和密码处理逻辑 - ResultPanel 表格高度计算重构 - 删除调试日志和临时文件 后端: - 新增 VisibleDatabases 字段到连接模型 - DeleteConnection 使用事务确保数据一致性 - LoadAllDatabases 支持 MySQL/MongoDB 数据库列表加载
27 lines
1.3 KiB
Go
27 lines
1.3 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
)
|
||
|
||
// DbConnection 数据库连接配置
|
||
type DbConnection struct {
|
||
ID uint `gorm:"primaryKey" json:"id"`
|
||
Name string `gorm:"type:varchar(100);not null" json:"name"` // 连接名称
|
||
Type string `gorm:"type:varchar(20);not null" json:"type"` // 数据库类型: mysql/redis/mongo
|
||
Host string `gorm:"type:varchar(255);not null" json:"host"` // 主机地址
|
||
Port int `gorm:"not null" json:"port"` // 端口
|
||
Username string `gorm:"type:varchar(100)" json:"username"` // 用户名
|
||
Password string `gorm:"type:varchar(500)" json:"-"` // 密码(加密存储,不返回)
|
||
Database string `gorm:"type:varchar(100)" json:"database"` // 数据库名(MySQL/MongoDB)
|
||
Options string `gorm:"type:text" json:"options"` // 额外选项(JSON格式)
|
||
VisibleDatabases string `gorm:"type:text" json:"visible_databases"` // 可见数据库列表(JSON数组,为空则全部可见)
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
}
|
||
|
||
// TableName 指定表名
|
||
func (DbConnection) TableName() string {
|
||
return "db_connection"
|
||
}
|