refactor: sqlexec组件重构优化、新增数据库相关系统参数配置、相关问题修复

This commit is contained in:
meilin.huang
2023-02-13 21:11:16 +08:00
parent 77aa724003
commit 70b586e45a
35 changed files with 2486 additions and 2120 deletions

View File

@@ -27,6 +27,16 @@ func SetStr(key, value string) {
rediscli.Set(key, value, 0)
}
// 删除指定key
func Del(key string) {
if rediscli.GetCli() == nil {
checkStrCache()
delete(strCache, key)
return
}
rediscli.Del(key)
}
func checkStrCache() {
if strCache == nil {
strCache = make(map[string]string)

View File

@@ -145,7 +145,7 @@ func Insert(model interface{}) error {
//
// @param list为数组类型 如 var users *[]User可指定为非model结构体即只包含需要返回的字段结构体
func ListBy(model interface{}, list interface{}, cols ...string) {
global.Db.Model(model).Select(cols).Where(model).Find(list)
global.Db.Model(model).Select(cols).Where(model).Order("id desc").Find(list)
}
// 获取满足model中不为空的字段值条件的所有数据.

View File

@@ -0,0 +1,27 @@
package utils
import "encoding/binary"
func Bytes2Int8(bytes []byte) int8 {
return int8(Byte2Uint16(bytes))
}
func Bytes2Int(bytes []byte) int {
return int(Byte2Uint64(bytes))
}
func Bytes2Int64(bytes []byte) int64 {
return int64(Byte2Uint64(bytes))
}
func Byte2Uint64(bytes []byte) uint64 {
return binary.LittleEndian.Uint64(bytes)
}
func Byte2Uint32(bytes []byte) uint32 {
return binary.LittleEndian.Uint32(bytes)
}
func Byte2Uint16(bytes []byte) uint16 {
return binary.LittleEndian.Uint16(bytes)
}

View File

@@ -2,6 +2,7 @@ package utils
import (
"encoding/json"
"mayfly-go/pkg/global"
)
func Json2Map(jsonStr string) map[string]interface{} {
@@ -12,3 +13,12 @@ func Json2Map(jsonStr string) map[string]interface{} {
_ = json.Unmarshal([]byte(jsonStr), &res)
return res
}
func ToJsonStr(val any) string {
if strBytes, err := json.Marshal(val); err != nil {
global.Log.Error("toJsonStr error: ", err)
return ""
} else {
return string(strBytes)
}
}