1 Star 0 Fork 0

bugsmo/go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
query.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
bugsmo 提交于 2024-06-01 22:06 . v1.0.0
package entgo
import (
"entgo.io/ent/dialect/sql"
_ "github.com/go-kratos/kratos/v2/encoding/json"
)
// BuildQuerySelector 构建分页过滤查询器
func BuildQuerySelector(
andFilterJsonString, orFilterJsonString string,
page, pageSize int32, noPaging bool,
orderBys []string, defaultOrderField string,
selectFields []string,
) (err error, whereSelectors []func(s *sql.Selector), querySelectors []func(s *sql.Selector)) {
err, whereSelectors = BuildFilterSelector(andFilterJsonString, orFilterJsonString)
if err != nil {
return err, nil, nil
}
var orderSelector func(s *sql.Selector)
err, orderSelector = BuildOrderSelector(orderBys, defaultOrderField)
if err != nil {
return err, nil, nil
}
pageSelector := BuildPaginationSelector(page, pageSize, noPaging)
var fieldSelector func(s *sql.Selector)
err, fieldSelector = BuildFieldSelector(selectFields)
if len(whereSelectors) > 0 {
querySelectors = append(querySelectors, whereSelectors...)
}
if orderSelector != nil {
querySelectors = append(querySelectors, orderSelector)
}
if pageSelector != nil {
querySelectors = append(querySelectors, pageSelector)
}
if fieldSelector != nil {
querySelectors = append(querySelectors, fieldSelector)
}
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ssxlt/go-utils.git
git@gitee.com:ssxlt/go-utils.git
ssxlt
go-utils
go-utils
entgo/v1.0.1

搜索帮助

0d507c66 1850385 C8b1a773 1850385