优化对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
|
// Date : 20:15 2022/10/20
|
||||||
func WithOrder(orderRuleList ...string) define.SetOption {
|
func WithOrder(orderRuleList ...string) define.SetOption {
|
||||||
return func(o *define.Option) {
|
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
|
o.Order = orderRuleList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -351,12 +362,7 @@ func WithOrder(orderRuleList ...string) define.SetOption {
|
|||||||
//
|
//
|
||||||
// Date : 15:09 2023/4/3
|
// Date : 15:09 2023/4/3
|
||||||
func WithOrderDesc(field string) define.SetOption {
|
func WithOrderDesc(field string) define.SetOption {
|
||||||
return func(o *define.Option) {
|
return WithOrder(field, "DESC")
|
||||||
if nil == o.Order {
|
|
||||||
o.Order = make([]string, 0)
|
|
||||||
}
|
|
||||||
o.Order = append(o.Order, field+" desc")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithOrderAsc 升序排序
|
// WithOrderAsc 升序排序
|
||||||
@ -365,12 +371,7 @@ func WithOrderDesc(field string) define.SetOption {
|
|||||||
//
|
//
|
||||||
// Date : 15:09 2023/4/3
|
// Date : 15:09 2023/4/3
|
||||||
func WithOrderAsc(field string) define.SetOption {
|
func WithOrderAsc(field string) define.SetOption {
|
||||||
return func(o *define.Option) {
|
return WithOrder(field, "ASC")
|
||||||
if nil == o.Order {
|
|
||||||
o.Order = make([]string, 0)
|
|
||||||
}
|
|
||||||
o.Order = append(o.Order, field+" asc")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newOption 生成新的option
|
// newOption 生成新的option
|
||||||
|
Loading…
Reference in New Issue
Block a user