mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 01:50:25 +08:00
对服务增加基础的数据统计/部分代码分Package
This commit is contained in:
33
internal/db/utils/utils.go
Normal file
33
internal/db/utils/utils.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package dbutils
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var SharedCacheLocker = sync.RWMutex{}
|
||||
|
||||
// 处理JSON字节Slice
|
||||
func JSONBytes(data []byte) []byte {
|
||||
if len(data) == 0 {
|
||||
return []byte("null")
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// 判断JSON是否不为空
|
||||
func IsNotNull(data string) bool {
|
||||
return len(data) > 0 && data != "null"
|
||||
}
|
||||
|
||||
// 构造Query
|
||||
func NewQuery(tx *dbs.Tx, dao dbs.DAOWrapper, adminId int64, userId int64) *dbs.Query {
|
||||
query := dao.Object().Query(tx)
|
||||
if adminId > 0 {
|
||||
//query.Attr("adminId", adminId)
|
||||
}
|
||||
if userId > 0 {
|
||||
query.Attr("userId", userId)
|
||||
}
|
||||
return query
|
||||
}
|
||||
Reference in New Issue
Block a user