2021-11-11 15:56:02 +08:00
|
|
|
package router
|
2021-04-16 15:10:07 +08:00
|
|
|
|
|
|
|
|
import (
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/internal/devops/api"
|
|
|
|
|
"mayfly-go/internal/devops/application"
|
|
|
|
|
sysApplication "mayfly-go/internal/sys/application"
|
|
|
|
|
"mayfly-go/pkg/ctx"
|
2021-04-16 15:10:07 +08:00
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func InitDbRouter(router *gin.RouterGroup) {
|
|
|
|
|
db := router.Group("dbs")
|
|
|
|
|
{
|
2022-04-22 17:49:21 +08:00
|
|
|
d := &api.Db{
|
2022-06-16 15:55:18 +08:00
|
|
|
DbApp: application.DbApp,
|
|
|
|
|
DbSqlExecApp: application.DbSqlExecApp,
|
|
|
|
|
MsgApp: sysApplication.MsgApp,
|
|
|
|
|
ProjectApp: application.ProjectApp,
|
2021-11-25 14:34:15 +08:00
|
|
|
}
|
2021-04-16 15:10:07 +08:00
|
|
|
// 获取所有数据库列表
|
|
|
|
|
db.GET("", func(c *gin.Context) {
|
|
|
|
|
rc := ctx.NewReqCtxWithGin(c)
|
2021-05-08 18:00:33 +08:00
|
|
|
rc.Handle(d.Dbs)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
2021-07-28 18:03:19 +08:00
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
saveDb := ctx.NewLogInfo("保存数据库信息").WithSave(true)
|
2021-07-28 18:03:19 +08:00
|
|
|
db.POST("", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).
|
|
|
|
|
WithLog(saveDb).
|
|
|
|
|
Handle(d.Save)
|
|
|
|
|
})
|
|
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
deleteDb := ctx.NewLogInfo("删除数据库信息").WithSave(true)
|
2021-12-20 20:42:52 +08:00
|
|
|
db.DELETE(":dbId", func(c *gin.Context) {
|
2021-07-28 18:03:19 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).
|
|
|
|
|
WithLog(deleteDb).
|
|
|
|
|
Handle(d.DeleteDb)
|
|
|
|
|
})
|
|
|
|
|
|
2021-08-18 17:57:33 +08:00
|
|
|
db.GET(":dbId/t-infos", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.TableInfos)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
db.GET(":dbId/t-index", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.TableIndex)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
db.GET(":dbId/t-create-ddl", func(c *gin.Context) {
|
2022-01-12 16:00:31 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.GetCreateTableDdl)
|
2021-08-18 17:57:33 +08:00
|
|
|
})
|
|
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
execSqlLog := ctx.NewLogInfo("执行Sql语句")
|
2022-06-16 15:55:18 +08:00
|
|
|
db.POST(":dbId/exec-sql", func(g *gin.Context) {
|
2022-07-14 11:39:12 +08:00
|
|
|
rc := ctx.NewReqCtxWithGin(g).WithLog(execSqlLog)
|
2021-07-28 18:03:19 +08:00
|
|
|
rc.Handle(d.ExecSql)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
|
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
execSqlFileLog := ctx.NewLogInfo("执行Sql文件").WithSave(true)
|
2021-11-25 14:34:15 +08:00
|
|
|
db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
|
2022-07-14 11:39:12 +08:00
|
|
|
ctx.NewReqCtxWithGin(g).
|
|
|
|
|
WithLog(execSqlFileLog).
|
|
|
|
|
Handle(d.ExecSqlFile)
|
2021-11-25 14:34:15 +08:00
|
|
|
})
|
|
|
|
|
|
2022-07-14 11:39:12 +08:00
|
|
|
dumpLog := ctx.NewLogInfo("导出sql文件").WithSave(true)
|
2022-06-30 16:42:25 +08:00
|
|
|
db.GET(":dbId/dump", func(g *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(g).
|
2022-07-14 11:39:12 +08:00
|
|
|
WithLog(dumpLog).
|
2022-06-30 16:42:25 +08:00
|
|
|
Handle(d.DumpSql)
|
|
|
|
|
})
|
|
|
|
|
|
2021-04-16 15:10:07 +08:00
|
|
|
db.GET(":dbId/t-metadata", func(c *gin.Context) {
|
2021-05-08 18:00:33 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.TableMA)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
db.GET(":dbId/c-metadata", func(c *gin.Context) {
|
2021-05-08 18:00:33 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.ColumnMA)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
2021-12-20 20:42:52 +08:00
|
|
|
|
2021-04-16 15:10:07 +08:00
|
|
|
db.GET(":dbId/hint-tables", func(c *gin.Context) {
|
2021-05-08 18:00:33 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.HintTables)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
|
|
|
|
|
2021-12-20 20:42:52 +08:00
|
|
|
/** db sql相关接口 */
|
|
|
|
|
|
2021-04-16 15:10:07 +08:00
|
|
|
db.POST(":dbId/sql", func(c *gin.Context) {
|
2021-07-28 18:03:19 +08:00
|
|
|
rc := ctx.NewReqCtxWithGin(c)
|
2021-05-08 18:00:33 +08:00
|
|
|
rc.Handle(d.SaveSql)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
db.GET(":dbId/sql", func(c *gin.Context) {
|
2021-05-08 18:00:33 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.GetSql)
|
2021-04-16 15:10:07 +08:00
|
|
|
})
|
2021-12-20 20:42:52 +08:00
|
|
|
|
|
|
|
|
db.DELETE(":dbId/sql", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.DeleteSql)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
db.GET(":dbId/sql-names", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(d.GetSqlNames)
|
|
|
|
|
})
|
2021-04-16 15:10:07 +08:00
|
|
|
}
|
|
|
|
|
}
|