forked from go-rel/rel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_query.go
50 lines (42 loc) · 936 Bytes
/
sort_query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package rel
// SortQuery defines sort information of query.
type SortQuery struct {
Field string
Sort int
}
// Build sort query.
func (sq SortQuery) Build(query *Query) {
query.SortQuery = append(query.SortQuery, sq)
}
// Asc returns true if sort is ascending.
func (sq SortQuery) Asc() bool {
return sq.Sort >= 0
}
// Desc returns true if s is descending.
func (sq SortQuery) Desc() bool {
return sq.Sort < 0
}
// SortAsc sorts field with ascending sort.
func SortAsc(field string) SortQuery {
return SortQuery{
Field: field,
Sort: 1,
}
}
// NewSortDesc sorts field with descending sort.
func SortDesc(field string) SortQuery {
return SortQuery{
Field: field,
Sort: -1,
}
}
var (
// NewSortAsc sorts field with ascending sort.
//
// Deprecated: use SortAsc instead
NewSortAsc = SortAsc
// NewSortDesc sorts field with descending sort.
//
// Deprecated: use SortDesc instead
NewSortDesc = SortDesc
)