增加从page + size构建limit/offset的方法

This commit is contained in:
白茶清欢 2023-10-14 21:47:04 +08:00
parent 40f5ba11ef
commit 2a7f06060d
1 changed files with 17 additions and 0 deletions

View File

@ -88,6 +88,23 @@ func WithLimit[T op_type.Int](limit T, offset T) SetOption {
}
}
// WithLimitByPageAndSize 通过page和size构建条件
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 21:42 2023/10/14
func WithLimitByPageAndSize[T op_type.Int](page T, size T) SetOption {
return func(o *Option) {
if size > 0 {
o.Limit = int(size)
}
if page <= 0 {
page = 1
}
o.Offset = int((page - 1) * size)
}
}
// WithIn 设置in条件
//
// Author : go_developer@163.com<白茶清欢>