优化对order语句的处理
This commit is contained in:
parent
a4cbda626d
commit
0005d1e8f7
25
option.go
25
option.go
@ -341,6 +341,17 @@ func WithOR(orConditionList ...define.SetOption) define.SetOption {
|
||||
// Date : 20:15 2022/10/20
|
||||
func WithOrder(orderRuleList ...string) define.SetOption {
|
||||
return func(o *define.Option) {
|
||||
if len(orderRuleList) != 2 {
|
||||
return
|
||||
}
|
||||
if len(orderRuleList[0]) == 0 {
|
||||
// 未指定排序字段
|
||||
return
|
||||
}
|
||||
if len(orderRuleList[1]) == 0 {
|
||||
// 未指定排序规则, 默认倒序
|
||||
orderRuleList[1] = "DESC"
|
||||
}
|
||||
o.Order = orderRuleList
|
||||
}
|
||||
}
|
||||
@ -351,12 +362,7 @@ func WithOrder(orderRuleList ...string) define.SetOption {
|
||||
//
|
||||
// Date : 15:09 2023/4/3
|
||||
func WithOrderDesc(field string) define.SetOption {
|
||||
return func(o *define.Option) {
|
||||
if nil == o.Order {
|
||||
o.Order = make([]string, 0)
|
||||
}
|
||||
o.Order = append(o.Order, field+" desc")
|
||||
}
|
||||
return WithOrder(field, "DESC")
|
||||
}
|
||||
|
||||
// WithOrderAsc 升序排序
|
||||
@ -365,12 +371,7 @@ func WithOrderDesc(field string) define.SetOption {
|
||||
//
|
||||
// Date : 15:09 2023/4/3
|
||||
func WithOrderAsc(field string) define.SetOption {
|
||||
return func(o *define.Option) {
|
||||
if nil == o.Order {
|
||||
o.Order = make([]string, 0)
|
||||
}
|
||||
o.Order = append(o.Order, field+" asc")
|
||||
}
|
||||
return WithOrder(field, "ASC")
|
||||
}
|
||||
|
||||
// newOption 生成新的option
|
||||
|
Loading…
Reference in New Issue
Block a user