添加删除接口,修改运行sql返回数据结构
This commit is contained in:
parent
1244feb7de
commit
1ff1347187
|
|
@ -211,7 +211,7 @@ func RunSQLWithOrder(sql string, db_ *gorm.DB) (result proto.SQLResult, err erro
|
|||
return result, err
|
||||
}
|
||||
for _, col := range columns {
|
||||
result.Columns = append(result.Columns, proto.SQLResultColumnsValue{Value: col})
|
||||
result.Columns = append(result.Columns, proto.SQLResultColumnsValue{Prop: col, Label: col})
|
||||
}
|
||||
|
||||
// 遍历每行数据
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ func SetDBManageGroup(router *gin.Engine) {
|
|||
dbm.POST("/update_db_manage", UpdateDBManageHandler) // 更新数据库管理信息
|
||||
dbm.POST("/del_db_manage", DeleteDBManageHandler) // 删除数据库管理信息
|
||||
dbm.POST("/del_dbm_sql_history", DeleteSQLRunHistoryHandler) // 删除SQL运行历史
|
||||
dbm.POST("/get_db_table_desc", GetDBTableDescHandler) // 获取数据库表描述
|
||||
}
|
||||
|
||||
func DeleteSQLRunHistoryHandler(c *gin.Context) {
|
||||
|
|
@ -179,3 +180,26 @@ func RunSQLHandler(c *gin.Context) {
|
|||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetDBTableDescHandler(c *gin.Context) {
|
||||
id, _ := c.Get("id")
|
||||
userID := int(id.(float64))
|
||||
|
||||
var req proto.GetDBTableDescReq
|
||||
var resp proto.GeneralResp
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
resp.Code = proto.ParameterError
|
||||
resp.Message = "请求参数解析错误"
|
||||
} else {
|
||||
tableDesc, err2 := service.GetDBTableDesc(&req, userID)
|
||||
if err2 != nil {
|
||||
resp.Code = proto.DBMGetTableDescFailed
|
||||
resp.Message = "获取数据库表描述失败: " + err2.Error()
|
||||
} else {
|
||||
resp.Code = proto.SuccessCode
|
||||
resp.Message = "获取数据库表描述成功"
|
||||
resp.Data = tableDesc
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
|
|
|||
10
proto/dbm.go
10
proto/dbm.go
|
|
@ -77,7 +77,9 @@ type SQLResult struct {
|
|||
}
|
||||
|
||||
type SQLResultColumnsValue struct {
|
||||
Value string `json:"value"`
|
||||
Prop string `json:"prop"`
|
||||
Label string `json:"label"`
|
||||
Attr string `json:"attr"`
|
||||
}
|
||||
|
||||
type DeleteDBManageReq struct {
|
||||
|
|
@ -92,3 +94,9 @@ type DeleteDBManageSQLHistoryReq struct {
|
|||
History_ID uint `json:"history_id" form:"history_id"` // SQL执行历史ID,如果为0则删除所有
|
||||
UserID uint `json:"user_id" form:"user_id"` // 用户ID
|
||||
}
|
||||
|
||||
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个
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,4 +87,5 @@ const (
|
|||
DBMUpdateFailed = 1004 // 更新数据库管理信息失败
|
||||
DBMDeleteFailed = 1005 // 删除数据库管理信息失败
|
||||
DBMRunSQLHistoryDeleteFailed = 1006 // 删除SQL运行历史失败
|
||||
DBMGetTableDescFailed = 1007 // 获取表描述信息失败
|
||||
)
|
||||
|
|
|
|||
|
|
@ -194,3 +194,22 @@ func DeleteSQLRunHistory(req *proto.DeleteDBManageSQLHistoryReq, userId int) err
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetDBTableDesc(req *proto.GetDBTableDescReq, userId int) (*proto.SQLResult, error) {
|
||||
//dbmInfo, err := dao.FindDBManageByID(req.DB_ID)
|
||||
//if err != nil {`
|
||||
// return nil, err
|
||||
//}
|
||||
//if dbmInfo.UserID != uint(userId) && GetUserByIDFromUserCenter(userId).Role != "admin" {
|
||||
// return nil, errors.New("unauthorized access to the database management system")
|
||||
//}
|
||||
//db_, err := GetGORMDBObject(&dbmInfo)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
//res, err := dao.GetDBTableDesc(db_, req.Table, req.GetType)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue