Skip to content

Commit

Permalink
新增:OrderIf、DescIf、DescIfElse、AscIf、AscIfElse排序方法
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jan 3, 2024
1 parent 3828ab2 commit f5ca202
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tableSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,60 @@ func (receiver *TableSet[Table]) Order(value any) *TableSet[Table] {
return session
}

// OrderIf 排序,当conditional==true时,使用排序
func (receiver *TableSet[Table]) OrderIf(conditional bool, value any) *TableSet[Table] {
if !conditional {
return receiver
}
return receiver.Order(value)
}

// Desc 倒序
func (receiver *TableSet[Table]) Desc(fieldName string) *TableSet[Table] {
session := receiver.getOrCreateSession()
session.orderList.Add(fieldName + " desc")
return session
}

// DescIf 倒序,当conditional==true时,使用倒序
func (receiver *TableSet[Table]) DescIf(conditional bool, fieldName string) *TableSet[Table] {
if !conditional {
return receiver
}
return receiver.Desc(fieldName)
}

// DescIfElse 倒序,当conditional==true时,使用trueFieldName倒序,否则使用falseFieldName倒序
func (receiver *TableSet[Table]) DescIfElse(conditional bool, trueFieldName string, falseFieldName string) *TableSet[Table] {
if conditional {
return receiver.Desc(trueFieldName)
}
return receiver.Desc(falseFieldName)
}

// Asc 正序
func (receiver *TableSet[Table]) Asc(fieldName string) *TableSet[Table] {
session := receiver.getOrCreateSession()
session.orderList.Add(fieldName + " asc")
return session
}

// AscIf 正序,当conditional==true时,使用正序
func (receiver *TableSet[Table]) AscIf(conditional bool, fieldName string) *TableSet[Table] {
if !conditional {
return receiver
}
return receiver.Asc(fieldName)
}

// AscIfElse 正序,当conditional==true时,使用trueFieldName正序,否则使用falseFieldName正序
func (receiver *TableSet[Table]) AscIfElse(conditional bool, trueFieldName string, falseFieldName string) *TableSet[Table] {
if conditional {
return receiver.Asc(trueFieldName)
}
return receiver.Asc(falseFieldName)
}

// Limit 限制记录数
func (receiver *TableSet[Table]) Limit(limit int) *TableSet[Table] {
session := receiver.getOrCreateSession()
Expand Down

0 comments on commit f5ca202

Please sign in to comment.