-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfindcommand.go
56 lines (45 loc) · 1.43 KB
/
findcommand.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
51
52
53
54
55
56
package filemaker
// SortAscending sets the sort order to ascending
const SortAscending = "ascend"
// SortDescending sets the sort order to descending
const SortDescending = "descend"
// FindCommand represents the findcommand
type FindCommand map[string]interface{}
// NewFindCommand returns a findrequest
func NewFindCommand(requests ...interface{}) FindCommand {
var query []interface{}
for _, request := range requests {
query = append(query, request)
}
var command = FindCommand{
"query": query,
}
return command
}
// Limit sets the limit for the number of records returned by the findcommand
func (c FindCommand) Limit(limit int) FindCommand {
c["limit"] = limit
return c
}
// Offset sets the offset for the records returned by the findcommand
func (c FindCommand) Offset(offset int) FindCommand {
c["offset"] = offset
return c
}
// Sort adds the specified sort rule to the findcommand
func (c FindCommand) Sort(fieldName, sortOrder string) FindCommand {
if c["sort"] == nil {
c["sort"] = []interface{}{}
}
c["sort"] = append(c["sort"].([]interface{}), map[string]string{"fieldName": fieldName, "sortOrder": sortOrder})
return c
}
// AddRequest appends a specified FindRequest to the FindCommand
func (c *FindCommand) AddRequest(request FindRequest) {
if query, ok := (*c)["query"]; ok {
(*c)["query"] = append(query.([]interface{}), request)
} else {
var query []interface{}
(*c)["query"] = append(query, request)
}
}