forked from doubledutch/go-force
-
Notifications
You must be signed in to change notification settings - Fork 1
/
query.go
75 lines (57 loc) · 1.8 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package force
import (
"fmt"
"net/url"
"strings"
)
const (
BaseQueryString = "SELECT %v FROM %v"
)
func BuildQuery(fields, table string, constraints []string, constraintJoin string) string {
query := fmt.Sprintf(BaseQueryString, fields, table)
if len(constraints) > 0 {
query += fmt.Sprintf(" WHERE %v", strings.Join(constraints, " "+constraintJoin+" "))
}
return query
}
func (forceApi *ForceApi) GetFields(table string, allowCustomFields bool) (fieldList string, err error) {
desc, err := forceApi.GetApiSObjectDescription(table)
if err != nil {
return "", err
}
fields := ""
for _, field := range desc.Fields {
if allowCustomFields || !strings.HasSuffix(field.Name, "__c") {
if fields != "" {
fields = fields + ","
}
fields = fields + field.Name
}
}
return fields, nil
}
// Use the Query resource to execute a SOQL query that returns all the results in a single response,
// or if needed, returns part of the results and an identifier used to retrieve the remaining results.
func (forceApi *ForceApi) Query(query string, out interface{}) (err error) {
uri := forceApi.apiResources[queryKey]
params := url.Values{
"q": {query},
}
err = forceApi.Get(uri, params, out)
return
}
// Use the QueryAll resource to execute a SOQL query that includes information about records that have
// been deleted because of a merge or delete. Use QueryAll rather than Query, because the Query resource
// will automatically filter out items that have been deleted.
func (forceApi *ForceApi) QueryAll(query string, out interface{}) (err error) {
uri := forceApi.apiResources[queryAllKey]
params := url.Values{
"q": {query},
}
err = forceApi.Get(uri, params, out)
return
}
func (forceApi *ForceApi) QueryNext(uri string, out interface{}) (err error) {
err = forceApi.Get(uri, nil, out)
return
}