-
Notifications
You must be signed in to change notification settings - Fork 104
/
bucket_collectionsmgrv2.go
146 lines (115 loc) · 3.86 KB
/
bucket_collectionsmgrv2.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package gocb
import "time"
// CollectionManagerV2 provides methods for performing collections management.
type CollectionManagerV2 struct {
getProvider func() (collectionsManagementProvider, error)
}
// GetAllScopes gets all scopes from the bucket.
func (cm *CollectionManagerV2) GetAllScopes(opts *GetAllScopesOptions) ([]ScopeSpec, error) {
if opts == nil {
opts = &GetAllScopesOptions{}
}
provider, err := cm.getProvider()
if err != nil {
return nil, err
}
return provider.GetAllScopes(opts)
}
// CreateCollectionSettings specifies settings for a collection to be created
type CreateCollectionSettings struct {
// MaxExpiry is the maximum expiry all documents in the collection can have.
// Defaults to the bucket-level setting.
// Value of -1 seconds (time.Duration(-1) * time.Second) denotes 'no expiry'.
MaxExpiry time.Duration
History *CollectionHistorySettings
}
// CreateCollection creates a new collection on the bucket.
func (cm *CollectionManagerV2) CreateCollection(scopeName string, collectionName string, settings *CreateCollectionSettings, opts *CreateCollectionOptions) error {
if scopeName == "" {
return makeInvalidArgumentsError("collection name cannot be empty")
}
if collectionName == "" {
return makeInvalidArgumentsError("scope name cannot be empty")
}
if settings == nil {
settings = &CreateCollectionSettings{}
}
if opts == nil {
opts = &CreateCollectionOptions{}
}
provider, err := cm.getProvider()
if err != nil {
return err
}
return provider.CreateCollection(scopeName, collectionName, settings, opts)
}
// UpdateCollectionSettings specifies the settings for a collection that should be updated.
type UpdateCollectionSettings struct {
// MaxExpiry is the maximum expiry all documents in the collection can have.
// Defaults to the bucket-level setting.
// Value of -1 seconds (time.Duration(-1) * time.Second) denotes 'no expiry'.
MaxExpiry time.Duration
History *CollectionHistorySettings
}
// UpdateCollection updates the settings of an existing collection.
func (cm *CollectionManagerV2) UpdateCollection(scopeName string, collectionName string, settings UpdateCollectionSettings, opts *UpdateCollectionOptions) error {
if scopeName == "" {
return makeInvalidArgumentsError("collection name cannot be empty")
}
if collectionName == "" {
return makeInvalidArgumentsError("scope name cannot be empty")
}
if opts == nil {
opts = &UpdateCollectionOptions{}
}
provider, err := cm.getProvider()
if err != nil {
return err
}
return provider.UpdateCollection(scopeName, collectionName, settings, opts)
}
// DropCollection removes a collection.
func (cm *CollectionManagerV2) DropCollection(scopeName string, collectionName string, opts *DropCollectionOptions) error {
if scopeName == "" {
return makeInvalidArgumentsError("collection name cannot be empty")
}
if collectionName == "" {
return makeInvalidArgumentsError("scope name cannot be empty")
}
if opts == nil {
opts = &DropCollectionOptions{}
}
provider, err := cm.getProvider()
if err != nil {
return err
}
return provider.DropCollection(scopeName, collectionName, opts)
}
// CreateScope creates a new scope on the bucket.
func (cm *CollectionManagerV2) CreateScope(scopeName string, opts *CreateScopeOptions) error {
if scopeName == "" {
return makeInvalidArgumentsError("scope name cannot be empty")
}
if opts == nil {
opts = &CreateScopeOptions{}
}
provider, err := cm.getProvider()
if err != nil {
return err
}
return provider.CreateScope(scopeName, opts)
}
// DropScope removes a scope.
func (cm *CollectionManagerV2) DropScope(scopeName string, opts *DropScopeOptions) error {
if scopeName == "" {
return makeInvalidArgumentsError("scope name cannot be empty")
}
if opts == nil {
opts = &DropScopeOptions{}
}
provider, err := cm.getProvider()
if err != nil {
return err
}
return provider.DropScope(scopeName, opts)
}