数据库连接情况
This commit is contained in:
@@ -48,6 +48,11 @@ var (
|
||||
CustomXormCommonUri = config.UriPrefix + "/databaseManagement/{apiVersion}/{databaseName}/{tableName}" // for internal
|
||||
CustomXormExtDataUri = config.UriPrefix + "/dataManagement/{apiVersion}/{dataStorage}/{dataObject}" // for external
|
||||
CustomXormDataSQLUri = config.UriPrefix + "/dataManagement/{apiVersion}/{dataStorage}/{dataObject}" // for external
|
||||
|
||||
// 查询数据库连接情况
|
||||
UriDbConnection = config.UriPrefix + "/dataManagement/{apiVersion}/dbConnection"
|
||||
// 终结非法的数据库连接
|
||||
UriDbStop = config.UriPrefix + "/dataManagement/{apiVersion}/dbStop"
|
||||
)
|
||||
|
||||
var xormResponse XormResponse
|
||||
@@ -680,3 +685,52 @@ func DatabaseDeleteData(w http.ResponseWriter, r *http.Request) {
|
||||
mapRow["data"] = row
|
||||
services.ResponseWithJson(w, http.StatusOK, mapRow)
|
||||
}
|
||||
|
||||
// 连接用户实例
|
||||
func DbConnection(w http.ResponseWriter, r *http.Request) {
|
||||
if dborm.DbClient.XEngine == nil {
|
||||
services.ResponseErrorWithJson(w, 400, "无连接")
|
||||
}
|
||||
// 查询实例
|
||||
result, err := dborm.DbClient.XEngine.QueryString("SHOW PROCESSLIST;")
|
||||
if err != nil {
|
||||
services.ResponseErrorWithJson(w, 500, err.Error())
|
||||
}
|
||||
filterData := []map[string]string{}
|
||||
for _, r := range result {
|
||||
if r["User"] != "system user" {
|
||||
filterData = append(filterData, r)
|
||||
}
|
||||
}
|
||||
// Sleep:连接处于空闲状态,没有执行任何操作。
|
||||
// Query:连接正在执行一个查询语句。
|
||||
// Execute:连接正在执行一个准备好的 SQL 语句。
|
||||
// Connect:连接正在建立但尚未完成。
|
||||
services.ResponseWithJson(w, 200, filterData)
|
||||
}
|
||||
|
||||
// 关闭数据库连接
|
||||
func DbStop(w http.ResponseWriter, r *http.Request) {
|
||||
if dborm.DbClient.XEngine == nil {
|
||||
services.ResponseErrorWithJson(w, 400, "无连接")
|
||||
}
|
||||
|
||||
// json 請求參數獲取
|
||||
var bodyArgs struct {
|
||||
ID string `json:"ID" validate:"required"`
|
||||
}
|
||||
err := services.ShouldBindJSON(r, &bodyArgs)
|
||||
if err != nil {
|
||||
log.Error("io.ReadAll is failed:", err)
|
||||
services.ResponseErrorWithJson(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 关闭
|
||||
rse, err := dborm.DbClient.XEngine.Exec("KILL ?;", bodyArgs.ID)
|
||||
if err != nil {
|
||||
services.ResponseErrorWithJson(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
services.ResponseWithJson(w, 200, rse)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user