支持设置排序规则

This commit is contained in:
白茶清欢 2022-10-20 20:22:23 +08:00
parent 3f5864f369
commit 932d75f020
2 changed files with 17 additions and 0 deletions

View File

@ -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 := ""

View File

@ -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
}
}