2025-08-19 22:43:31 +08:00
|
|
|
|
package proto
|
|
|
|
|
|
|
2025-08-21 21:46:29 +08:00
|
|
|
|
import (
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
|
)
|
2025-08-19 22:43:31 +08:00
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
DB_TYPE_MYSQL = 0 // DBTypeMySQL MySQL数据库
|
|
|
|
|
|
DB_TYPE_POSTGRES = 1 // DBTypePostgres PostgreSQL数据库
|
|
|
|
|
|
DB_TYPE_SQLITE = 2 // DBTypeSQLite SQLite数据库
|
|
|
|
|
|
DB_TYPE_SQLSERVER = 3 // DBTypeSQLServer SQL Server数据库
|
|
|
|
|
|
DB_TYPE_ORACLE = 4 // DBTypeOracle Oracle数据库
|
|
|
|
|
|
DB_TYPE_MONGODB = 5 // DBTypeMongoDB MongoDB数据库
|
|
|
|
|
|
DB_TYPE_REDIS = 6 // DBTypeRedis Redis数据库
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type RunSQLRequest struct {
|
|
|
|
|
|
SQL string `json:"sql" form:"sql"` // SQL语句
|
|
|
|
|
|
DB_ID uint `json:"db_id" form:"db_id"` // 数据库ID
|
|
|
|
|
|
UserID uint `json:"user_id" form:"user_id"` // 用户ID
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type DBManage struct {
|
|
|
|
|
|
gorm.Model
|
|
|
|
|
|
UserID uint `gorm:"column:user_id"` // 用户ID
|
|
|
|
|
|
DB_IP string `gorm:"column:db_ip;type:varchar(255);uniqueIndex:idx_db_ip"` // 数据库IP
|
|
|
|
|
|
DB_Port uint `gorm:"column:db_port"` // 数据库端口
|
|
|
|
|
|
DB_NAME string `gorm:"column:db_name;type:varchar(255);uniqueIndex:idx_db_name"` // 数据库名称
|
|
|
|
|
|
DB_User string `gorm:"column:db_user;type:varchar(255);uniqueIndex:idx_db_user"` // 数据库用户名
|
|
|
|
|
|
DB_Password string `gorm:"column:db_password;type:varchar(255);uniqueIndex:idx_db_password"` // 数据库密码
|
|
|
|
|
|
DB_Type uint `gorm:"column:db_type"` // 数据库类型: 0为mysql,1为postgres,2为sqlite,3为sqlserver,4为oracle,5为mongodb,6为redis
|
|
|
|
|
|
DB_Desc string `gorm:"column:db_desc;type:varchar(255)"` // 数据库描述
|
|
|
|
|
|
DB_STATUS uint `gorm:"column:db_status"` // 数据库状态: 0为未连接,1为已连接,2为连接失败
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type SQLRunHistory struct {
|
|
|
|
|
|
gorm.Model
|
|
|
|
|
|
UserID uint `gorm:"column:user_id"` // 用户ID
|
|
|
|
|
|
SQL string `gorm:"column:sql;type:text"` // 执行的SQL语句
|
|
|
|
|
|
DB_ID uint `gorm:"column:db_id"` // 数据库ID
|
|
|
|
|
|
Status uint `gorm:"column:status"` // 执行状态: 0为成功,1为失败
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type CreateDBManageReq struct {
|
|
|
|
|
|
DB_IP string `json:"db_ip" form:"db_ip"` // 数据库IP
|
|
|
|
|
|
DB_Port uint `json:"db_port" form:"db_port"` // 数据库端口
|
|
|
|
|
|
DB_NAME string `json:"db_name" form:"db_name"` // 数据库名称
|
|
|
|
|
|
DB_User string `json:"db_user" form:"db_user"` // 数据库用户名
|
|
|
|
|
|
DB_Password string `json:"db_password" form:"db_password"` // 数据库密码
|
|
|
|
|
|
DB_Type uint `json:"db_type" form:"db_type"` // 数据库类型: 0为mysql,1为postgres,2为sqlite,3为sqlserver,4为oracle,5为mongodb,6为redis
|
2025-08-22 22:08:35 +08:00
|
|
|
|
DB_Desc string `json:"db_desc" form:"db_desc"` // 数据库描述备注
|
2025-08-19 22:43:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type UpdateDBManageReq struct {
|
|
|
|
|
|
DB_ID uint `json:"db_id" form:"db_id"` // 数据库ID
|
|
|
|
|
|
DB_IP string `json:"db_ip" form:"db_ip"` // 数据库IP
|
|
|
|
|
|
DB_Port uint `json:"db_port" form:"db_port"` // 数据库端口
|
|
|
|
|
|
DB_NAME string `json:"db_name" form:"db_name"` // 数据库名称
|
|
|
|
|
|
DB_User string `json:"db_user" form:"db_user"` // 数据库用户名
|
|
|
|
|
|
DB_Password string `json:"db_password" form:"db_password"` // 数据库密码
|
|
|
|
|
|
DB_Type uint `json:"db_type" form:"db_type"` // 数据库类型: 0为mysql,1为postgres,2为sqlite,3为sqlserver,4为oracle,5为mongodb,6为redis
|
2025-08-22 22:08:35 +08:00
|
|
|
|
DB_Desc string `json:"db_desc" form:"db_desc"` // 数据库描述备注
|
2025-08-19 22:43:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type GetDBManageReq struct {
|
|
|
|
|
|
DB_ID uint `json:"db_id" form:"db_id"` // 数据库ID
|
|
|
|
|
|
GET_TYPE int `json:"get_type" form:"get_type"` // 获取类型: 0获取自己,1为获取全部(管理员权限)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type GetSQLRunHistoryReq struct {
|
|
|
|
|
|
DB_ID uint `json:"db_id" form:"db_id"` // 数据库ID
|
|
|
|
|
|
GET_TYPE int `json:"get_type" form:"get_type"` // 获取类型: 0获取自己,1为获取全部(管理员权限)
|
|
|
|
|
|
}
|
2025-08-20 22:28:36 +08:00
|
|
|
|
|
|
|
|
|
|
// SQLResult 包含查询结果的列名顺序和对应数据
|
|
|
|
|
|
type SQLResult struct {
|
2025-08-21 21:46:29 +08:00
|
|
|
|
Columns []SQLResultColumnsValue // 列名顺序(与 SQL 查询的列顺序一致)
|
2025-08-20 22:28:36 +08:00
|
|
|
|
Rows []map[string]interface{} // 每行数据(map 便于按列名访问)
|
|
|
|
|
|
}
|
2025-08-21 21:46:29 +08:00
|
|
|
|
|
|
|
|
|
|
type SQLResultColumnsValue struct {
|
2025-08-22 20:43:25 +08:00
|
|
|
|
Prop string `json:"prop"`
|
|
|
|
|
|
Label string `json:"label"`
|
|
|
|
|
|
Attr string `json:"attr"`
|
2025-08-21 21:46:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type DeleteDBManageReq struct {
|
|
|
|
|
|
DB_ID uint `json:"db_id" form:"db_id"` // 数据库ID
|
|
|
|
|
|
Del_Type uint `json:"del_type" form:"del_type"` // 删除类型: 0为删除单条,1为所有
|
|
|
|
|
|
UserID uint `json:"user_id" form:"user_id"` // 用户ID
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type DeleteDBManageSQLHistoryReq struct {
|
|
|
|
|
|
DB_ID uint `json:"db_id" form:"db_id"` // 数据库ID
|
|
|
|
|
|
Del_Type uint `json:"del_type" form:"del_type"` // 删除类型: 0为删除单条,1为所有
|
|
|
|
|
|
History_ID uint `json:"history_id" form:"history_id"` // SQL执行历史ID,如果为0则删除所有
|
|
|
|
|
|
UserID uint `json:"user_id" form:"user_id"` // 用户ID
|
|
|
|
|
|
}
|
2025-08-22 20:43:25 +08:00
|
|
|
|
|
|
|
|
|
|
type GetDBTableDescReq struct {
|
|
|
|
|
|
DB_ID uint `json:"db_id" form:"db_id"` // 数据库ID
|
|
|
|
|
|
Table string `json:"table" form:"table"` // 数据库表名
|
|
|
|
|
|
GetType int `json:"get_type" form:"get_type"` // 获取类型: 0获取全部,1获取1个
|
|
|
|
|
|
}
|