Files
mayfly-go/server/internal/db/router/db.go

115 lines
2.8 KiB
Go
Raw Normal View History

package router
2021-04-16 15:10:07 +08:00
import (
2022-09-09 18:26:08 +08:00
"mayfly-go/internal/db/api"
"mayfly-go/internal/db/application"
sysapp "mayfly-go/internal/sys/application"
2022-10-26 20:49:29 +08:00
tagapp "mayfly-go/internal/tag/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")
{
d := &api.Db{
2022-09-09 18:26:08 +08:00
DbApp: application.GetDbApp(),
DbSqlExecApp: application.GetDbSqlExecApp(),
MsgApp: sysapp.GetMsgApp(),
2022-10-26 20:49:29 +08:00
TagApp: tagapp.GetTagTreeApp(),
}
2021-04-16 15:10:07 +08:00
// 获取所有数据库列表
db.GET("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.Dbs)
2021-04-16 15:10:07 +08:00
})
saveDb := ctx.NewLogInfo("保存数据库信息").WithSave(true)
db.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(saveDb).
Handle(d.Save)
})
// 获取数据库实例的所有数据库名
db.POST("databases", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
Handle(d.GetDatabaseNames)
})
db.GET(":dbId/pwd", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetDbPwd)
})
deleteDb := ctx.NewLogInfo("删除数据库信息").WithSave(true)
db.DELETE(":dbId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(deleteDb).
Handle(d.DeleteDb)
})
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) {
ctx.NewReqCtxWithGin(c).Handle(d.GetCreateTableDdl)
})
execSqlLog := ctx.NewLogInfo("执行Sql语句")
db.POST(":dbId/exec-sql", func(g *gin.Context) {
rc := ctx.NewReqCtxWithGin(g).WithLog(execSqlLog)
rc.Handle(d.ExecSql)
2021-04-16 15:10:07 +08:00
})
execSqlFileLog := ctx.NewLogInfo("执行Sql文件").WithSave(true)
db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g).
WithLog(execSqlFileLog).
Handle(d.ExecSqlFile)
})
dumpLog := ctx.NewLogInfo("导出sql文件").WithSave(true)
db.GET(":dbId/dump", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g).
WithLog(dumpLog).
Handle(d.DumpSql)
})
2021-04-16 15:10:07 +08:00
db.GET(":dbId/t-metadata", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.TableMA)
2021-04-16 15:10:07 +08:00
})
db.GET(":dbId/c-metadata", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.ColumnMA)
2021-04-16 15:10:07 +08:00
})
2021-04-16 15:10:07 +08:00
db.GET(":dbId/hint-tables", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.HintTables)
2021-04-16 15:10:07 +08:00
})
/** db sql相关接口 */
2021-04-16 15:10:07 +08:00
db.POST(":dbId/sql", func(c *gin.Context) {
rc := ctx.NewReqCtxWithGin(c)
rc.Handle(d.SaveSql)
2021-04-16 15:10:07 +08:00
})
db.GET(":dbId/sql", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).Handle(d.GetSql)
2021-04-16 15:10:07 +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
}
}