增加两个数据库相关调试命令

This commit is contained in:
刘祥超
2022-04-08 15:09:33 +08:00
parent 4e18129c6c
commit ad416dddec
2 changed files with 42 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/iwind/TeaGo/Tea"
_ "github.com/iwind/TeaGo/bootstrap"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
"github.com/iwind/gosock/pkg/gosock"
"log"
"os"
@@ -97,6 +98,31 @@ func main() {
}
}
})
app.On("db.stmt.prepare", func() {
var sock = gosock.NewTmpSock(teaconst.ProcessName)
reply, err := sock.Send(&gosock.Command{Code: "db.stmt.prepare"})
if err != nil {
fmt.Println("[ERROR]" + err.Error())
} else {
var isOn = maps.NewMap(reply.Params).GetBool("isOn")
if isOn {
fmt.Println("show statements: on")
} else {
fmt.Println("show statements: off")
}
}
})
app.On("db.stmt.count", func() {
var sock = gosock.NewTmpSock(teaconst.ProcessName)
reply, err := sock.Send(&gosock.Command{Code: "db.stmt.count"})
if err != nil {
fmt.Println("[ERROR]" + err.Error())
} else {
var count = maps.NewMap(reply.Params).GetInt("count")
fmt.Println("prepared statements count: " + types.String(count))
}
})
app.Run(func() {
nodes.NewAPINode().Start()
})

View File

@@ -585,8 +585,22 @@ func (this *APINode) listenSock() error {
_ = cmd.Reply(&gosock.Command{
Params: map[string]interface{}{"debug": teaconst.Debug},
})
case "db.stmt":
dbs.ShowPreparedStatements = true
case "db.stmt.prepare":
dbs.ShowPreparedStatements = !dbs.ShowPreparedStatements
_ = cmd.Reply(&gosock.Command{
Params: map[string]interface{}{"isOn": dbs.ShowPreparedStatements},
})
case "db.stmt.count":
db, _ := dbs.Default()
if db != nil {
_ = cmd.Reply(&gosock.Command{
Params: map[string]interface{}{"count": db.StmtManager().Len()},
})
} else {
_ = cmd.Reply(&gosock.Command{
Params: map[string]interface{}{"count": 0},
})
}
}
})