forked from ProjectWIND/ProjectWIND
将数据库api导入到js插件
This commit is contained in:
parent
753c6dc0ca
commit
8a49ded455
103
core/api.go
103
core/api.go
@ -818,7 +818,108 @@ func (a *apiInfo) Log(content string, args ...interface{}) {
|
||||
}
|
||||
|
||||
//database模块
|
||||
//数据库部分允许字符串变量的读写操作,允许获取配置项操作
|
||||
// //数据库部分允许字符串变量的读写操作,允许获取配置项操作
|
||||
// func (ai *AppInfo) VarSet(dataMap string, unit string, id string, key string, value string) {
|
||||
// if ai.dbHandler != nil {
|
||||
// ai.dbHandler.Set(ai.Name, dataMap, unit, id, key, value)
|
||||
// }
|
||||
// }
|
||||
|
||||
// // VarGet 获取变量
|
||||
// func (ai *AppInfo) VarGet(dataMap string, unit string, id string, key string) (string, bool) {
|
||||
// if ai.dbHandler != nil {
|
||||
// res, ok := ai.dbHandler.Get(ai.Name, dataMap, unit, id, key, false)
|
||||
// if !ok {
|
||||
// return "", false
|
||||
// }
|
||||
// resStr, ok := res.(string)
|
||||
// if !ok {
|
||||
// return "", false
|
||||
// }
|
||||
// return resStr, true
|
||||
// }
|
||||
// return "", false
|
||||
// }
|
||||
|
||||
// // GetIntConfig 获取整数配置
|
||||
// func (ai *AppInfo) GetIntConfig(dataMap string, key string) (int64, bool) {
|
||||
// if ai.dbHandler != nil {
|
||||
// res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "number", key, true)
|
||||
// if !ok {
|
||||
// return 0, false
|
||||
// }
|
||||
// resInt, ok := res.(int64)
|
||||
// if !ok {
|
||||
// return 0, false
|
||||
// }
|
||||
// return resInt, true
|
||||
// }
|
||||
// return 0, false
|
||||
// }
|
||||
|
||||
// // GetStringConfig 获取字符串配置
|
||||
// func (ai *AppInfo) GetStringConfig(dataMap string, key string) (string, bool) {
|
||||
// if ai.dbHandler != nil {
|
||||
// res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "string", key, true)
|
||||
// if !ok {
|
||||
// return "", false
|
||||
// }
|
||||
// resStr, ok := res.(string)
|
||||
// if !ok {
|
||||
// return "", false
|
||||
// }
|
||||
// return resStr, true
|
||||
// }
|
||||
// return "", false
|
||||
// }
|
||||
|
||||
// // GetFloatConfig 获取浮点数配置
|
||||
// func (ai *AppInfo) GetFloatConfig(dataMap string, key string) (float64, bool) {
|
||||
// if ai.dbHandler != nil {
|
||||
// res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "float", key, true)
|
||||
// if !ok {
|
||||
// return 0, false
|
||||
// }
|
||||
// resFloat, ok := res.(float64)
|
||||
// if !ok {
|
||||
// return 0, false
|
||||
// }
|
||||
// return resFloat, true
|
||||
// }
|
||||
// return 0, false
|
||||
// }
|
||||
|
||||
// // GetIntSliceConfig 获取整数切片配置
|
||||
// func (ai *AppInfo) GetIntSliceConfig(dataMap string, key string) ([]int64, bool) {
|
||||
// if ai.dbHandler != nil {
|
||||
// res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "number_slice", key, true)
|
||||
// if !ok {
|
||||
// return nil, false
|
||||
// }
|
||||
// resSlice, ok := res.([]int64)
|
||||
// if !ok {
|
||||
// return nil, false
|
||||
// }
|
||||
// return resSlice, true
|
||||
// }
|
||||
// return nil, false
|
||||
// }
|
||||
|
||||
// // GetStringSliceConfig 获取字符串切片配置
|
||||
// func (ai *AppInfo) GetStringSliceConfig(dataMap string, key string) ([]string, bool) {
|
||||
// if ai.dbHandler != nil {
|
||||
// res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "string_slice", key, true)
|
||||
// if !ok {
|
||||
// return nil, false
|
||||
// }
|
||||
// resSlice, ok := res.([]string)
|
||||
// if !ok {
|
||||
// return nil, false
|
||||
// }
|
||||
// return resSlice, true
|
||||
// }
|
||||
// return nil, false
|
||||
// }
|
||||
|
||||
// 文件管理模块
|
||||
//TODO: 文件管理模块待实现
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
"github.com/dop251/goja"
|
||||
)
|
||||
|
||||
var CmdMap = make(map[string]wba.Cmd)
|
||||
|
6
utils.go
6
utils.go
@ -362,7 +362,7 @@ func startDatabase() {
|
||||
time.Sleep(time.Second * 1)
|
||||
// 读写测试
|
||||
// for i := 0; i < 10; i++ {
|
||||
// data, ok := database.Get("user", "test", "test"+fmt.Sprintf("%d", i))
|
||||
// data, ok := database.Get("go", "go", "user", "test", "test"+fmt.Sprintf("%d", i), false)
|
||||
// if !ok {
|
||||
// LOG.Error("Failed to get data from database")
|
||||
// continue
|
||||
@ -372,12 +372,12 @@ func startDatabase() {
|
||||
// }
|
||||
// time.Sleep(time.Second * 1)
|
||||
// for i := 0; i < 10; i++ {
|
||||
// database.Set("user", "test", "test"+fmt.Sprintf("%d", i), "test"+fmt.Sprintf("%d", 1000+i))
|
||||
// database.Set("go", "go", "user", "test", "test"+fmt.Sprintf("%d", i), "test"+fmt.Sprintf("%d", 1000+i))
|
||||
// time.Sleep(time.Second * 1)
|
||||
// }
|
||||
// time.Sleep(time.Second * 1)
|
||||
// for i := 0; i < 10; i++ {
|
||||
// data, ok := database.Get("user", "test", "test"+fmt.Sprintf("%d", i))
|
||||
// data, ok := database.Get("go", "go", "user", "test", "test"+fmt.Sprintf("%d", i), false)
|
||||
// if !ok {
|
||||
// LOG.Error("Failed to get data from database")
|
||||
// continue
|
||||
|
30
wba/wind.go
30
wba/wind.go
@ -287,7 +287,7 @@ type AppInfo struct {
|
||||
MetaEventHandler func(msg MetaEventInfo)
|
||||
ScheduledTasks map[string]ScheduledTaskInfo
|
||||
API map[string]interface{}
|
||||
dbHandler DataBaseHandler
|
||||
DbHandler DataBaseHandler
|
||||
}
|
||||
|
||||
func (ai AppInfo) Get() AppInfo {
|
||||
@ -312,15 +312,15 @@ func (ai *AppInfo) AddScheduledTask(task ScheduledTaskInfo) {
|
||||
}
|
||||
|
||||
func (ai *AppInfo) VarSet(dataMap string, unit string, id string, key string, value string) {
|
||||
if ai.dbHandler != nil {
|
||||
ai.dbHandler.Set(ai.Name, dataMap, unit, id, key, value)
|
||||
if ai.DbHandler != nil {
|
||||
ai.DbHandler.Set(ai.Name, dataMap, unit, id, key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// VarGet 获取变量
|
||||
func (ai *AppInfo) VarGet(dataMap string, unit string, id string, key string) (string, bool) {
|
||||
if ai.dbHandler != nil {
|
||||
res, ok := ai.dbHandler.Get(ai.Name, dataMap, unit, id, key, false)
|
||||
if ai.DbHandler != nil {
|
||||
res, ok := ai.DbHandler.Get(ai.Name, dataMap, unit, id, key, false)
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
@ -335,8 +335,8 @@ func (ai *AppInfo) VarGet(dataMap string, unit string, id string, key string) (s
|
||||
|
||||
// GetIntConfig 获取整数配置
|
||||
func (ai *AppInfo) GetIntConfig(dataMap string, key string) (int64, bool) {
|
||||
if ai.dbHandler != nil {
|
||||
res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "number", key, true)
|
||||
if ai.DbHandler != nil {
|
||||
res, ok := ai.DbHandler.Get(ai.Name, dataMap, "config", "number", key, true)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
@ -351,8 +351,8 @@ func (ai *AppInfo) GetIntConfig(dataMap string, key string) (int64, bool) {
|
||||
|
||||
// GetStringConfig 获取字符串配置
|
||||
func (ai *AppInfo) GetStringConfig(dataMap string, key string) (string, bool) {
|
||||
if ai.dbHandler != nil {
|
||||
res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "string", key, true)
|
||||
if ai.DbHandler != nil {
|
||||
res, ok := ai.DbHandler.Get(ai.Name, dataMap, "config", "string", key, true)
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
@ -367,8 +367,8 @@ func (ai *AppInfo) GetStringConfig(dataMap string, key string) (string, bool) {
|
||||
|
||||
// GetFloatConfig 获取浮点数配置
|
||||
func (ai *AppInfo) GetFloatConfig(dataMap string, key string) (float64, bool) {
|
||||
if ai.dbHandler != nil {
|
||||
res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "float", key, true)
|
||||
if ai.DbHandler != nil {
|
||||
res, ok := ai.DbHandler.Get(ai.Name, dataMap, "config", "float", key, true)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
@ -383,8 +383,8 @@ func (ai *AppInfo) GetFloatConfig(dataMap string, key string) (float64, bool) {
|
||||
|
||||
// GetIntSliceConfig 获取整数切片配置
|
||||
func (ai *AppInfo) GetIntSliceConfig(dataMap string, key string) ([]int64, bool) {
|
||||
if ai.dbHandler != nil {
|
||||
res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "number_slice", key, true)
|
||||
if ai.DbHandler != nil {
|
||||
res, ok := ai.DbHandler.Get(ai.Name, dataMap, "config", "number_slice", key, true)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
@ -399,8 +399,8 @@ func (ai *AppInfo) GetIntSliceConfig(dataMap string, key string) ([]int64, bool)
|
||||
|
||||
// GetStringSliceConfig 获取字符串切片配置
|
||||
func (ai *AppInfo) GetStringSliceConfig(dataMap string, key string) ([]string, bool) {
|
||||
if ai.dbHandler != nil {
|
||||
res, ok := ai.dbHandler.Get(ai.Name, dataMap, "config", "string_slice", key, true)
|
||||
if ai.DbHandler != nil {
|
||||
res, ok := ai.DbHandler.Get(ai.Name, dataMap, "config", "string_slice", key, true)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user