forked from go-rel/rel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort_query.go
More file actions
38 lines (32 loc) · 710 Bytes
/
sort_query.go
File metadata and controls
38 lines (32 loc) · 710 Bytes
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
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
}
// NewSortAsc sorts field with ascending sort.
func NewSortAsc(field string) SortQuery {
return SortQuery{
Field: field,
Sort: 1,
}
}
// NewSortDesc sorts field with descending sort.
func NewSortDesc(field string) SortQuery {
return SortQuery{
Field: field,
Sort: -1,
}
}