支持设置排序规则
This commit is contained in:
parent
3f5864f369
commit
932d75f020
5
base.go
5
base.go
@ -158,6 +158,11 @@ func (b *BaseDao) setTxCondition(tx *gorm.DB, table string, optionFuncList ...Se
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
for _, orderRule := range o.Order {
|
||||
tx = tx.Order(orderRule)
|
||||
}
|
||||
|
||||
// or 语句
|
||||
if nil != o.OR {
|
||||
expression := ""
|
||||
|
12
option.go
12
option.go
@ -40,6 +40,7 @@ type Option struct {
|
||||
Like map[string]string `json:"like"` // like 语句
|
||||
NotLike map[string]string `json:"not_like"` // not like 语句
|
||||
NotEqual map[string]interface{} `json:"not_equal"` // != 语句
|
||||
Order []string `json:"order"` // 排序规则
|
||||
OR []*ORCondition `json:"or"` // or 语句, or 和其他属性 and 关系, 内部 OR 关系
|
||||
}
|
||||
|
||||
@ -294,3 +295,14 @@ func WithOR(orConditionList ...*ORCondition) SetOption {
|
||||
o.OR = append(o.OR, orConditionList...)
|
||||
}
|
||||
}
|
||||
|
||||
// WithOrder 设置排序规则
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:15 2022/10/20
|
||||
func WithOrder(orderRuleList ...string) SetOption {
|
||||
return func(o *Option) {
|
||||
o.Order = orderRuleList
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user