-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathquery.go
53 lines (44 loc) · 1.42 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
// Package force provides access to Salesforce various APIs
package force
import (
"fmt"
"net/url"
)
// Query is used for retrieving query performance feedback without executing
// the query
func (c *Client) Query(query string, v interface{}) (err error) {
endpoint := fmt.Sprintf("/query/?q=%v", url.QueryEscape(query))
req, err := c.NewRequest("GET", endpoint, nil)
if err != nil {
return
}
err = c.Do(req, &v)
return
}
// QueryExplain is used for retrieving query performance feedback without
// executing the query
func (c *Client) QueryExplain(query string) (explain QueryExplainResponse, err error) {
endpoint := fmt.Sprintf("/query/?explain=%v", url.QueryEscape(query))
req, err := c.NewRequest("GET", endpoint, nil)
if err != nil {
return
}
err = c.Do(req, &explain)
return
}
// QueryExplainResponse is returned by QueryExplain
type QueryExplainResponse struct {
Plans []struct {
Cardinality int `json:"cardinality"`
Fields []string `json:"fields"`
LeadingOperationType string `json:"leadingOperationType"`
RelativeCost float64 `json:"relativeCost"`
SobjectCardinality int `json:"sobjectCardinality"`
SobjectType string `json:"sobjectType"`
Notes []struct {
Description string `json:"description"`
Fields []string `json:"fields"`
TableEnumOrID string `json:"tableEnumOrId"`
} `json:"notes"`
} `json:"plans"`
}