mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
refactor: sqlexec组件重构优化、新增数据库相关系统参数配置、相关问题修复
This commit is contained in:
10
server/pkg/cache/str_cache.go
vendored
10
server/pkg/cache/str_cache.go
vendored
@@ -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)
|
||||
|
||||
@@ -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中不为空的字段值条件的所有数据.
|
||||
|
||||
27
server/pkg/utils/byte_utils.go
Normal file
27
server/pkg/utils/byte_utils.go
Normal 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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user