support raw order

This commit is contained in:
Anker Jam
2020-10-26 00:01:15 +08:00
parent 56fa213a6e
commit 7d4e88c1b9
3 changed files with 34 additions and 16 deletions

View File

@@ -2,4 +2,5 @@ package clauses
const (
ExprSep = "__"
ExprDot = "."
)

View File

@@ -1,5 +1,7 @@
package clauses
import "strings"
type Sort int8
const (
@@ -33,6 +35,18 @@ func (o *Order) GetSort() Sort {
return o.sort
}
func (o *Order) SortString() string {
switch o.GetSort() {
case SortAscending:
return "ASC"
case SortDescending:
return "DESC"
}
return ``
}
func (o *Order) IsRaw() bool {
return o.isRaw
}
@@ -41,10 +55,10 @@ func ParseOrder(expressions ...string) []*Order {
var orders []*Order
for _, expression := range expressions {
sort := SortAscending
column := expression
if expression[0] == '-' {
column := strings.ReplaceAll(expression, ExprSep, ExprDot)
if column[0] == '-' {
sort = SortDescending
column = expression[1:]
column = column[1:]
}
orders = append(orders, &Order{