43 lines
721 B
Go
43 lines
721 B
Go
|
package mySql
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func (t *Query) OrderByRaw(s string) *Query {
|
||
|
t.orderBy = s
|
||
|
return t
|
||
|
}
|
||
|
func (t *Query) OrderBy(s string, b string) *Query {
|
||
|
//看有没有.
|
||
|
countSplit := strings.SplitN(s, ".", 2)
|
||
|
if len(countSplit) == 2 {
|
||
|
t.orderBy = fmt.Sprintf("`%s`.`%s` %s", countSplit[0], countSplit[1], b)
|
||
|
} else {
|
||
|
t.orderBy = fmt.Sprintf("`%s` %s", s, b)
|
||
|
}
|
||
|
return t
|
||
|
}
|
||
|
|
||
|
func (t *Query) OrderByDesc(s string) *Query {
|
||
|
t.OrderBy(s, "DESC")
|
||
|
return t
|
||
|
}
|
||
|
|
||
|
func (t *Query) OrderByAsc(s string) *Query {
|
||
|
t.OrderBy(s, "ASC")
|
||
|
return t
|
||
|
}
|
||
|
|
||
|
func (t *Query) OrderIsByDesc(isDesc bool, s string) *Query {
|
||
|
if s != "" {
|
||
|
if isDesc {
|
||
|
t.OrderByDesc(s)
|
||
|
} else {
|
||
|
t.OrderByAsc(s)
|
||
|
}
|
||
|
}
|
||
|
return t
|
||
|
}
|