访问日志关键词支持完整的URL/优化Like语句

This commit is contained in:
刘祥超
2022-03-27 12:22:47 +08:00
parent 803f11659c
commit 7aea2fd48c
27 changed files with 134 additions and 75 deletions

View File

@@ -2,24 +2,12 @@ package dbutils
import (
"github.com/iwind/TeaGo/dbs"
"strings"
"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)
@@ -31,3 +19,22 @@ func NewQuery(tx *dbs.Tx, dao dbs.DAOWrapper, adminId int64, userId int64) *dbs.
}
return query
}
// QuoteLikeKeyword 处理关键词中的特殊字符
func QuoteLikeKeyword(keyword string) string {
keyword = strings.ReplaceAll(keyword, "%", "\\%")
keyword = strings.ReplaceAll(keyword, "_", "\\_")
return keyword
}
func QuoteLike(keyword string) string {
return "%" + QuoteLikeKeyword(keyword) + "%"
}
func QuoteLikePrefix(keyword string) string {
return QuoteLikeKeyword(keyword) + "%"
}
func QuoteLikeSuffix(keyword string) string {
return "%" + QuoteLikeKeyword(keyword)
}