Files
EdgeAPI/internal/db/models/utils.go

29 lines
526 B
Go
Raw Normal View History

2020-09-17 10:16:00 +08:00
package models
import "github.com/iwind/TeaGo/dbs"
2020-09-17 10:16:00 +08:00
// 处理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(dao dbs.DAOWrapper, adminId int64, userId int64) *dbs.Query {
query := dao.Object().Query()
if adminId > 0 {
query.Attr("adminId", adminId)
}
if userId > 0 {
query.Attr("userId", userId)
}
return query
}