Files
EdgeAPI/internal/db/utils/utils.go
2022-03-22 19:30:30 +08:00

34 lines
628 B
Go

package dbutils
import (
"github.com/iwind/TeaGo/dbs"
"sync"
)
var SharedCacheLocker = sync.RWMutex{}
// JSONBytes 处理JSON字节Slice
func JSONBytes(data []byte) []byte {
if len(data) == 0 {
return []byte("null")
}
return data
}
// IsNotNull 判断JSON是否不为空
func IsNotNull(data string) bool {
return len(data) > 0 && data != "null"
}
// NewQuery 构造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
}