功能: - 支持配置 MySQL/MongoDB 可见数据库列表 - 连接删除时自动清理关联数据并关闭连接池 - 新增加载数据库列表 API - 数据库错误提示优化 改进: - 代码简化:消除重复的表单验证和密码处理逻辑 - ResultPanel 表格高度计算重构 - 删除调试日志和临时文件 后端: - 新增 VisibleDatabases 字段到连接模型 - DeleteConnection 使用事务确保数据一致性 - LoadAllDatabases 支持 MySQL/MongoDB 数据库列表加载
74 lines
1.7 KiB
Go
74 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"u-desk/internal/storage"
|
|
"u-desk/internal/storage/models"
|
|
)
|
|
|
|
func main() {
|
|
// 初始化数据库
|
|
db, err := storage.Init()
|
|
if err != nil {
|
|
log.Fatalf("数据库初始化失败: %v", err)
|
|
}
|
|
|
|
fmt.Println("=== 数据库连接配置调试工具 ===")
|
|
fmt.Println()
|
|
|
|
// 列出所有连接
|
|
var connections []models.DbConnection
|
|
result := db.Order("id").Find(&connections)
|
|
if result.Error != nil {
|
|
log.Fatalf("查询失败: %v", result.Error)
|
|
}
|
|
|
|
fmt.Printf("当前有 %d 个连接配置:\n", len(connections))
|
|
fmt.Println()
|
|
|
|
for _, conn := range connections {
|
|
fmt.Printf("ID: %d\n", conn.ID)
|
|
fmt.Printf(" 名称: %s\n", conn.Name)
|
|
fmt.Printf(" 类型: %s\n", conn.Type)
|
|
fmt.Printf(" 主机: %s:%d\n", conn.Host, conn.Port)
|
|
fmt.Printf(" 用户名: %s\n", conn.Username)
|
|
fmt.Printf(" 创建时间: %s\n", conn.CreatedAt.Format("2006-01-02 15:04:05"))
|
|
fmt.Println()
|
|
}
|
|
|
|
// 询问用户操作
|
|
var choice int
|
|
fmt.Print("请选择操作:\n")
|
|
fmt.Print("1. 删除指定 ID 的连接\n")
|
|
fmt.Print("2. 列出连接详情\n")
|
|
fmt.Print("0. 退出\n")
|
|
fmt.Print("请输入: ")
|
|
fmt.Scanln(&choice)
|
|
|
|
if choice == 1 {
|
|
var id uint
|
|
fmt.Print("请输入要删除的连接 ID: ")
|
|
fmt.Scanln(&id)
|
|
|
|
// 确认
|
|
var confirm string
|
|
fmt.Printf("确认删除 ID=%d 的连接吗?(y/N): ", id)
|
|
fmt.Scanln(&confirm)
|
|
|
|
if confirm == "y" || confirm == "Y" {
|
|
result := db.Delete(&models.DbConnection{}, id)
|
|
if result.Error != nil {
|
|
log.Printf("删除失败: %v", result.Error)
|
|
} else {
|
|
fmt.Printf("删除成功!影响行数: %d\n", result.RowsAffected)
|
|
}
|
|
} else {
|
|
fmt.Println("已取消删除")
|
|
}
|
|
}
|
|
|
|
fmt.Println("\n工具退出")
|
|
}
|