-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyticsquery_options.go
76 lines (61 loc) · 1.66 KB
/
analyticsquery_options.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
76
package gocb
import (
"context"
"strings"
"time"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
)
// AnalyticsQueryOptions is the set of options available to an Analytics query.
type AnalyticsQueryOptions struct {
ServerSideTimeout time.Duration
Context context.Context
ParentSpanContext opentracing.SpanContext
Pretty bool
ContextID string
RawParam map[string]interface{}
Priority bool
PositionalParameters []interface{}
NamedParameters map[string]interface{}
// Experimental: This API is subject to change at any time.
Deferred bool
}
func (opts *AnalyticsQueryOptions) toMap(statement string) (map[string]interface{}, error) {
execOpts := make(map[string]interface{})
execOpts["statement"] = statement
if opts.ServerSideTimeout != 0 {
execOpts["timeout"] = opts.ServerSideTimeout.String()
}
if opts.Pretty {
execOpts["pretty"] = opts.Pretty
}
if opts.ContextID != "" {
execOpts["client_context_id"] = opts.ContextID
}
if opts.Priority {
execOpts["priority"] = -1
}
if opts.Deferred {
execOpts["mode"] = "async"
}
if opts.PositionalParameters != nil && opts.NamedParameters != nil {
return nil, errors.New("Positional and named parameters must be used exclusively")
}
if opts.PositionalParameters != nil {
execOpts["args"] = opts.PositionalParameters
}
if opts.NamedParameters != nil {
for key, value := range opts.NamedParameters {
if !strings.HasPrefix(key, "$") {
key = "$" + key
}
execOpts[key] = value
}
}
if opts.RawParam != nil {
for k, v := range opts.RawParam {
execOpts[k] = v
}
}
return execOpts, nil
}