-
Notifications
You must be signed in to change notification settings - Fork 104
/
collection.go
113 lines (89 loc) · 3.12 KB
/
collection.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package gocb
// Collection represents a single collection.
type Collection struct {
collectionName string
scope string
bucket *Bucket
timeoutsConfig TimeoutsConfig
transcoder Transcoder
retryStrategyWrapper *coreRetryStrategyWrapper
compressor *compressor
useMutationTokens bool
opController opController
getKvProvider func() (kvProvider, error)
getKvBulkProvider func() (kvBulkProvider, error)
getQueryIndexProvider func() (queryIndexProvider, error)
}
func newCollection(scope *Scope, collectionName string) *Collection {
return &Collection{
collectionName: collectionName,
scope: scope.Name(),
bucket: scope.bucket,
timeoutsConfig: scope.timeoutsConfig,
transcoder: scope.transcoder,
retryStrategyWrapper: scope.retryStrategyWrapper,
compressor: scope.compressor,
useMutationTokens: scope.useMutationTokens,
opController: scope.opController,
getKvProvider: scope.getKvProvider,
getKvBulkProvider: scope.getKvBulkProvider,
getQueryIndexProvider: scope.getQueryIndexProvider,
}
}
func (c *Collection) name() string {
return c.collectionName
}
// ScopeName returns the name of the scope to which this collection belongs.
func (c *Collection) ScopeName() string {
return c.scope
}
// Bucket returns the bucket to which this collection belongs.
// UNCOMMITTED: This API may change in the future.
func (c *Collection) Bucket() *Bucket {
return c.bucket
}
// Name returns the name of the collection.
func (c *Collection) Name() string {
return c.collectionName
}
// QueryIndexes returns a CollectionQueryIndexManager for managing query indexes.
// UNCOMMITTED: This API may change in the future.
func (c *Collection) QueryIndexes() *CollectionQueryIndexManager {
return &CollectionQueryIndexManager{
controller: &providerController[queryIndexProvider]{
get: c.getQueryIndexProvider,
opController: c.opController,
},
c: c,
}
}
func (c *Collection) startKvOpTrace(operationName string, tracectx RequestSpanContext, tracer RequestTracer, noAttributes bool) RequestSpan {
span := tracer.RequestSpan(tracectx, operationName)
if !noAttributes {
span.SetAttribute(spanAttribDBNameKey, c.bucket.Name())
span.SetAttribute(spanAttribDBCollectionNameKey, c.Name())
span.SetAttribute(spanAttribDBScopeNameKey, c.ScopeName())
span.SetAttribute(spanAttribServiceKey, "kv")
span.SetAttribute(spanAttribOperationKey, operationName)
}
span.SetAttribute(spanAttribDBSystemKey, spanAttribDBSystemValue)
return span
}
func (c *Collection) bucketName() string {
return c.bucket.Name()
}
func (c *Collection) isDefault() bool {
return (c.scope == "" || c.scope == "_default") && (c.collectionName == "" || c.collectionName == "_default")
}
func (c *Collection) kvController() *providerController[kvProvider] {
return &providerController[kvProvider]{
get: c.getKvProvider,
opController: c.opController,
}
}
func (c *Collection) kvBulkController() *providerController[kvBulkProvider] {
return &providerController[kvBulkProvider]{
get: c.getKvBulkProvider,
opController: c.opController,
}
}