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"
2023-01-14 16:29:52 +08:00
"mayfly-go/pkg/req"
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) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.Dbs)
2021-04-16 15:10:07 +08:00
})
2023-01-14 16:29:52 +08:00
saveDb := req.NewLogInfo("db-保存数据库信息").WithSave(true)
db.POST("", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).
WithLog(saveDb).
Handle(d.Save)
})
// 获取数据库实例的所有数据库名
db.POST("databases", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).
Handle(d.GetDatabaseNames)
})
db.GET(":dbId/pwd", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.GetDbPwd)
})
2023-01-14 16:29:52 +08:00
deleteDb := req.NewLogInfo("db-删除数据库信息").WithSave(true)
db.DELETE(":dbId", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).
WithLog(deleteDb).
Handle(d.DeleteDb)
})
db.GET(":dbId/t-infos", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.TableInfos)
})
db.GET(":dbId/t-index", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.TableIndex)
})
db.GET(":dbId/t-create-ddl", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.GetCreateTableDdl)
})
2023-01-14 16:29:52 +08:00
execSqlLog := req.NewLogInfo("db-执行Sql")
db.POST(":dbId/exec-sql", func(g *gin.Context) {
2023-01-14 16:29:52 +08:00
rc := req.NewCtxWithGin(g).WithLog(execSqlLog)
rc.Handle(d.ExecSql)
2021-04-16 15:10:07 +08:00
})
2023-01-14 16:29:52 +08:00
execSqlFileLog := req.NewLogInfo("db-执行Sql文件").WithSave(true)
db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(g).
WithLog(execSqlFileLog).
Handle(d.ExecSqlFile)
})
2023-01-14 16:29:52 +08:00
dumpLog := req.NewLogInfo("db-导出sql文件").WithSave(true)
db.GET(":dbId/dump", func(g *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(g).
WithLog(dumpLog).
Handle(d.DumpSql)
})
2021-04-16 15:10:07 +08:00
db.GET(":dbId/t-metadata", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.TableMA)
2021-04-16 15:10:07 +08:00
})
db.GET(":dbId/c-metadata", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(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) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(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) {
2023-01-14 16:29:52 +08:00
rc := req.NewCtxWithGin(c)
rc.Handle(d.SaveSql)
2021-04-16 15:10:07 +08:00
})
db.GET(":dbId/sql", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.GetSql)
2021-04-16 15:10:07 +08:00
})
db.DELETE(":dbId/sql", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.DeleteSql)
})
db.GET(":dbId/sql-names", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(d.GetSqlNames)
})
2021-04-16 15:10:07 +08:00
}
}