forked from couchbase/gocb
/
analyticsquery.go
63 lines (54 loc) · 1.73 KB
/
analyticsquery.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
package gocb
import "time"
// AnalyticsQuery represents a pending Analytics query.
type AnalyticsQuery struct {
options map[string]interface{}
}
// NewAnalyticsQuery creates a new AnalyticsQuery object from a query string.
func NewAnalyticsQuery(statement string) *AnalyticsQuery {
nq := &AnalyticsQuery{
options: make(map[string]interface{}),
}
nq.options["statement"] = statement
return nq
}
// ServerSideTimeout indicates the maximum time to wait for this query to complete.
func (aq *AnalyticsQuery) ServerSideTimeout(timeout time.Duration) *AnalyticsQuery {
aq.options["timeout"] = timeout.String()
return aq
}
// Pretty indicates whether the response should be nicely formatted.
func (aq *AnalyticsQuery) Pretty(pretty bool) *AnalyticsQuery {
aq.options["pretty"] = pretty
return aq
}
// ContextId sets the client context id for the request, for use with tracing.
func (aq *AnalyticsQuery) ContextId(clientContextId string) *AnalyticsQuery {
aq.options["client_context_id"] = clientContextId
return aq
}
// RawParam allows specifying custom query options.
func (aq *AnalyticsQuery) RawParam(name string, value interface{}) *AnalyticsQuery {
aq.options[name] = value
return aq
}
// Priority sets whether or not the query should be run with priority status.
func (aq *AnalyticsQuery) Priority(priority bool) *AnalyticsQuery {
if priority {
aq.options["priority"] = -1
} else {
delete(aq.options, "priority")
}
return aq
}
// Deferred sets whether or not the query should be run as a deferred query.
//
// Experimental: This API is subject to change at any time.
func (aq *AnalyticsQuery) Deferred(deferred bool) *AnalyticsQuery {
if deferred {
aq.options["mode"] = "async"
} else {
delete(aq.options, "mode")
}
return aq
}