couchbase 3.5.0-arm64-darwin-22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +202 -0
- data/README.md +154 -0
- data/ext/extconf.rb +0 -0
- data/lib/active_support/cache/couchbase_store.rb +339 -0
- data/lib/couchbase/3.0/libcouchbase.bundle +0 -0
- data/lib/couchbase/3.1/libcouchbase.bundle +0 -0
- data/lib/couchbase/3.2/libcouchbase.bundle +0 -0
- data/lib/couchbase/3.3/libcouchbase.bundle +0 -0
- data/lib/couchbase/analytics_options.rb +107 -0
- data/lib/couchbase/authenticator.rb +64 -0
- data/lib/couchbase/binary_collection.rb +128 -0
- data/lib/couchbase/binary_collection_options.rb +24 -0
- data/lib/couchbase/bucket.rb +144 -0
- data/lib/couchbase/cluster.rb +460 -0
- data/lib/couchbase/cluster_registry.rb +49 -0
- data/lib/couchbase/collection.rb +705 -0
- data/lib/couchbase/collection_options.rb +399 -0
- data/lib/couchbase/config_profiles.rb +55 -0
- data/lib/couchbase/configuration.rb +56 -0
- data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
- data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
- data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
- data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
- data/lib/couchbase/datastructures.rb +24 -0
- data/lib/couchbase/diagnostics.rb +181 -0
- data/lib/couchbase/errors.rb +376 -0
- data/lib/couchbase/json_transcoder.rb +39 -0
- data/lib/couchbase/key_value_scan.rb +117 -0
- data/lib/couchbase/libcouchbase.rb +6 -0
- data/lib/couchbase/logger.rb +85 -0
- data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
- data/lib/couchbase/management/bucket_manager.rb +443 -0
- data/lib/couchbase/management/collection_manager.rb +470 -0
- data/lib/couchbase/management/collection_query_index_manager.rb +222 -0
- data/lib/couchbase/management/query_index_manager.rb +617 -0
- data/lib/couchbase/management/scope_search_index_manager.rb +198 -0
- data/lib/couchbase/management/search_index_manager.rb +424 -0
- data/lib/couchbase/management/user_manager.rb +468 -0
- data/lib/couchbase/management/view_index_manager.rb +237 -0
- data/lib/couchbase/management.rb +29 -0
- data/lib/couchbase/mutation_state.rb +63 -0
- data/lib/couchbase/options.rb +2837 -0
- data/lib/couchbase/protostellar/binary_collection.rb +55 -0
- data/lib/couchbase/protostellar/bucket.rb +51 -0
- data/lib/couchbase/protostellar/client.rb +99 -0
- data/lib/couchbase/protostellar/cluster.rb +163 -0
- data/lib/couchbase/protostellar/collection.rb +152 -0
- data/lib/couchbase/protostellar/connect_options.rb +63 -0
- data/lib/couchbase/protostellar/error_handling.rb +203 -0
- data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +61 -0
- data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +35 -0
- data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +57 -0
- data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +36 -0
- data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +61 -0
- data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +37 -0
- data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +72 -0
- data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +44 -0
- data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +52 -0
- data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +70 -0
- data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +36 -0
- data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +97 -0
- data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +46 -0
- data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +57 -0
- data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/routing/v1/routing_pb.rb +52 -0
- data/lib/couchbase/protostellar/generated/routing/v1/routing_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +99 -0
- data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +57 -0
- data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +36 -0
- data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +51 -0
- data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated.rb +9 -0
- data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
- data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
- data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
- data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
- data/lib/couchbase/protostellar/management.rb +24 -0
- data/lib/couchbase/protostellar/request.rb +78 -0
- data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
- data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
- data/lib/couchbase/protostellar/request_generator/admin/collection.rb +94 -0
- data/lib/couchbase/protostellar/request_generator/admin/query.rb +130 -0
- data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
- data/lib/couchbase/protostellar/request_generator/kv.rb +474 -0
- data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
- data/lib/couchbase/protostellar/request_generator/search.rb +387 -0
- data/lib/couchbase/protostellar/request_generator.rb +26 -0
- data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
- data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
- data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
- data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
- data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
- data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
- data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
- data/lib/couchbase/protostellar/response_converter.rb +26 -0
- data/lib/couchbase/protostellar/retry/action.rb +38 -0
- data/lib/couchbase/protostellar/retry/orchestrator.rb +60 -0
- data/lib/couchbase/protostellar/retry/reason.rb +67 -0
- data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
- data/lib/couchbase/protostellar/retry/strategies.rb +26 -0
- data/lib/couchbase/protostellar/retry.rb +28 -0
- data/lib/couchbase/protostellar/scope.rb +57 -0
- data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
- data/lib/couchbase/protostellar/timeouts.rb +83 -0
- data/lib/couchbase/protostellar.rb +29 -0
- data/lib/couchbase/query_options.rb +120 -0
- data/lib/couchbase/railtie.rb +45 -0
- data/lib/couchbase/raw_binary_transcoder.rb +37 -0
- data/lib/couchbase/raw_json_transcoder.rb +38 -0
- data/lib/couchbase/raw_string_transcoder.rb +40 -0
- data/lib/couchbase/scope.rb +256 -0
- data/lib/couchbase/search_options.rb +1622 -0
- data/lib/couchbase/subdoc.rb +290 -0
- data/lib/couchbase/transcoder_flags.rb +62 -0
- data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
- data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
- data/lib/couchbase/utils/time.rb +69 -0
- data/lib/couchbase/utils.rb +21 -0
- data/lib/couchbase/version.rb +23 -0
- data/lib/couchbase/view_options.rb +65 -0
- data/lib/couchbase.rb +28 -0
- data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
- metadata +191 -0
@@ -0,0 +1,470 @@
|
|
1
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "rubygems/deprecate"
|
16
|
+
|
17
|
+
require "couchbase/errors"
|
18
|
+
require "couchbase/options"
|
19
|
+
|
20
|
+
module Couchbase
|
21
|
+
module Management
|
22
|
+
module Options
|
23
|
+
module Collection
|
24
|
+
# Options for {CollectionManager#get_all_scopes}
|
25
|
+
class GetAllScopes < ::Couchbase::Options::Base
|
26
|
+
# Creates an instance of options for {CollectionManager#get_all_scopes}
|
27
|
+
#
|
28
|
+
# @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
|
29
|
+
# @param [Proc, nil] retry_strategy the custom retry strategy, if set
|
30
|
+
# @param [Hash, nil] client_context the client context data, if set
|
31
|
+
# @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
|
32
|
+
#
|
33
|
+
# @yieldparam [GetAllScopes] self
|
34
|
+
def initialize(timeout: nil,
|
35
|
+
retry_strategy: nil,
|
36
|
+
client_context: nil,
|
37
|
+
parent_span: nil)
|
38
|
+
super
|
39
|
+
yield self if block_given?
|
40
|
+
end
|
41
|
+
|
42
|
+
DEFAULT = GetAllScopes.new.freeze
|
43
|
+
end
|
44
|
+
|
45
|
+
# Options for {CollectionManager#create_scope}
|
46
|
+
class CreateScope < ::Couchbase::Options::Base
|
47
|
+
# Creates an instance of options for {CollectionManager#create_scope}
|
48
|
+
#
|
49
|
+
# @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
|
50
|
+
# @param [Proc, nil] retry_strategy the custom retry strategy, if set
|
51
|
+
# @param [Hash, nil] client_context the client context data, if set
|
52
|
+
# @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
|
53
|
+
#
|
54
|
+
# @yieldparam [CreateScope] self
|
55
|
+
def initialize(timeout: nil,
|
56
|
+
retry_strategy: nil,
|
57
|
+
client_context: nil,
|
58
|
+
parent_span: nil)
|
59
|
+
super
|
60
|
+
yield self if block_given?
|
61
|
+
end
|
62
|
+
|
63
|
+
DEFAULT = CreateScope.new.freeze
|
64
|
+
end
|
65
|
+
|
66
|
+
# Options for {CollectionManager#drop_scope}
|
67
|
+
class DropScope < ::Couchbase::Options::Base
|
68
|
+
# Creates an instance of options for {CollectionManager#drop_scope}
|
69
|
+
#
|
70
|
+
# @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
|
71
|
+
# @param [Proc, nil] retry_strategy the custom retry strategy, if set
|
72
|
+
# @param [Hash, nil] client_context the client context data, if set
|
73
|
+
# @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
|
74
|
+
#
|
75
|
+
# @yieldparam [DropScope] self
|
76
|
+
def initialize(timeout: nil,
|
77
|
+
retry_strategy: nil,
|
78
|
+
client_context: nil,
|
79
|
+
parent_span: nil)
|
80
|
+
super
|
81
|
+
yield self if block_given?
|
82
|
+
end
|
83
|
+
|
84
|
+
DEFAULT = DropScope.new.freeze
|
85
|
+
end
|
86
|
+
|
87
|
+
# Options for {CollectionManager#create_collection}
|
88
|
+
class CreateCollection < ::Couchbase::Options::Base
|
89
|
+
# Creates an instance of options for {CollectionManager#create_collection}
|
90
|
+
#
|
91
|
+
# @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
|
92
|
+
# @param [Proc, nil] retry_strategy the custom retry strategy, if set
|
93
|
+
# @param [Hash, nil] client_context the client context data, if set
|
94
|
+
# @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
|
95
|
+
#
|
96
|
+
# @yieldparam [CreateCollection] self
|
97
|
+
def initialize(timeout: nil,
|
98
|
+
retry_strategy: nil,
|
99
|
+
client_context: nil,
|
100
|
+
parent_span: nil)
|
101
|
+
super
|
102
|
+
yield self if block_given?
|
103
|
+
end
|
104
|
+
|
105
|
+
DEFAULT = CreateCollection.new.freeze
|
106
|
+
end
|
107
|
+
|
108
|
+
# Options for {CollectionManager#update_collection}
|
109
|
+
class UpdateCollection < ::Couchbase::Options::Base
|
110
|
+
# Creates an instance of options for {CollectionManager#update_collection}
|
111
|
+
#
|
112
|
+
# @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
|
113
|
+
# @param [Proc, nil] retry_strategy the custom retry strategy, if set
|
114
|
+
# @param [Hash, nil] client_context the client context data, if set
|
115
|
+
# @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
|
116
|
+
#
|
117
|
+
# @yieldparam [UpdateCollection] self
|
118
|
+
def initialize(timeout: nil,
|
119
|
+
retry_strategy: nil,
|
120
|
+
client_context: nil,
|
121
|
+
parent_span: nil)
|
122
|
+
super
|
123
|
+
yield self if block_given?
|
124
|
+
end
|
125
|
+
|
126
|
+
DEFAULT = UpdateCollection.new.freeze
|
127
|
+
end
|
128
|
+
|
129
|
+
# Options for {CollectionManager#drop_collection}
|
130
|
+
class DropCollection < ::Couchbase::Options::Base
|
131
|
+
# Creates an instance of options for {CollectionManager#drop_collection}
|
132
|
+
#
|
133
|
+
# @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
|
134
|
+
# @param [Proc, nil] retry_strategy the custom retry strategy, if set
|
135
|
+
# @param [Hash, nil] client_context the client context data, if set
|
136
|
+
# @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
|
137
|
+
#
|
138
|
+
# @yieldparam [DropCollection] self
|
139
|
+
def initialize(timeout: nil,
|
140
|
+
retry_strategy: nil,
|
141
|
+
client_context: nil,
|
142
|
+
parent_span: nil)
|
143
|
+
super
|
144
|
+
yield self if block_given?
|
145
|
+
end
|
146
|
+
|
147
|
+
DEFAULT = DropCollection.new.freeze
|
148
|
+
end
|
149
|
+
|
150
|
+
# rubocop:disable Naming/MethodName constructor shortcuts
|
151
|
+
module_function
|
152
|
+
|
153
|
+
# Construct {GetAllScopes} options for {CollectionManager#get_all_scopes}
|
154
|
+
#
|
155
|
+
# @return [GetAllScopes]
|
156
|
+
def GetAllScopes(**args)
|
157
|
+
GetAllScopes.new(**args)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Construct {CreateScope} options for {CollectionManager#create_scope}
|
161
|
+
#
|
162
|
+
# @return [CreateScope]
|
163
|
+
def CreateScope(**args)
|
164
|
+
CreateScope.new(**args)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Construct {DropScope} options for {CollectionManager#drop_scope}
|
168
|
+
#
|
169
|
+
# @return [DropScope]
|
170
|
+
def DropScope(**args)
|
171
|
+
DropScope.new(**args)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Construct {CreateCollection} options for {CollectionManager#create_collection}
|
175
|
+
#
|
176
|
+
# @return [CreateCollection]
|
177
|
+
def CreateCollection(**args)
|
178
|
+
CreateCollection.new(**args)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Construct {DropCollection} options for {CollectionManager#drop_collection}
|
182
|
+
#
|
183
|
+
# @return [DropCollection]
|
184
|
+
def DropCollection(**args)
|
185
|
+
DropCollection.new(**args)
|
186
|
+
end
|
187
|
+
|
188
|
+
# rubocop:enable Naming/MethodName
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
class CollectionManager
|
193
|
+
extend Gem::Deprecate
|
194
|
+
|
195
|
+
alias inspect to_s
|
196
|
+
|
197
|
+
# @param [Couchbase::Backend] backend
|
198
|
+
# @param [String] bucket_name
|
199
|
+
def initialize(backend, bucket_name)
|
200
|
+
@backend = backend
|
201
|
+
@bucket_name = bucket_name
|
202
|
+
end
|
203
|
+
|
204
|
+
# Get all scopes
|
205
|
+
#
|
206
|
+
# @param [Options::Collection::GetAllScopes] options
|
207
|
+
#
|
208
|
+
# @return [Array<ScopeSpec>]
|
209
|
+
def get_all_scopes(options = Options::Collection::GetAllScopes.new)
|
210
|
+
res = @backend.scope_get_all(@bucket_name, options.to_backend)
|
211
|
+
res[:scopes].map do |s|
|
212
|
+
ScopeSpec.new do |scope|
|
213
|
+
scope.name = s[:name]
|
214
|
+
scope.collections = s[:collections].map do |c|
|
215
|
+
CollectionSpec.new do |collection|
|
216
|
+
collection.name = c[:name]
|
217
|
+
collection.scope_name = s[:name]
|
218
|
+
collection.max_expiry = c[:max_expiry]
|
219
|
+
collection.history = c[:history]
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# Get a scope by name
|
227
|
+
#
|
228
|
+
# @param [String] scope_name name of the scope
|
229
|
+
# @param [GetScopeOptions] options
|
230
|
+
#
|
231
|
+
# @deprecated Use {#get_all_scopes} with filter by name
|
232
|
+
#
|
233
|
+
# @return [ScopeSpec]
|
234
|
+
#
|
235
|
+
# @raise [Error::ScopeNotFound]
|
236
|
+
def get_scope(scope_name, options = GetScopeOptions.new)
|
237
|
+
get_all_scopes(Options::Collection::GetAllScopes(timeout: options.timeout))
|
238
|
+
.find { |scope| scope.name == scope_name } or raise Error::ScopeNotFound, "unable to find scope #{scope_name}"
|
239
|
+
end
|
240
|
+
|
241
|
+
deprecate :get_scope, :get_all_scopes, 2021, 6
|
242
|
+
|
243
|
+
# Creates a new scope
|
244
|
+
#
|
245
|
+
# @param [String] scope_name name of the scope
|
246
|
+
# @param [Options::Collection::CreateScope] options
|
247
|
+
#
|
248
|
+
# @return void
|
249
|
+
#
|
250
|
+
# @raise [ArgumentError]
|
251
|
+
def create_scope(scope_name, options = Options::Collection::CreateScope.new)
|
252
|
+
@backend.scope_create(@bucket_name, scope_name, options.to_backend)
|
253
|
+
end
|
254
|
+
|
255
|
+
# Removes a scope
|
256
|
+
#
|
257
|
+
# @param [String] scope_name name of the scope
|
258
|
+
# @param [Options::Collection::DropScope] options
|
259
|
+
#
|
260
|
+
# @return void
|
261
|
+
#
|
262
|
+
# @raise [Error::ScopeNotFound]
|
263
|
+
def drop_scope(scope_name, options = Options::Collection::DropScope.new)
|
264
|
+
@backend.scope_drop(@bucket_name, scope_name, options.to_backend)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Creates a new collection
|
268
|
+
# @overload create_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT,
|
269
|
+
# options = Options::Collection::CreateCollection::DEFAULT)
|
270
|
+
# @param [String] scope_name the name of the scope the collection will be created in
|
271
|
+
# @param [String] collection_name the name of the collection to be created
|
272
|
+
# @param [CreateCollectionSettings] settings settings for the new collection
|
273
|
+
# @param [Options::Collection::CreateCollection] options
|
274
|
+
#
|
275
|
+
# @overload create_collection(collection, options = Options::Collection::CreateCollection)
|
276
|
+
# @param [CollectionSpec] collection specification of the collection
|
277
|
+
# @param [Options::Collection::CreateCollection] options
|
278
|
+
#
|
279
|
+
# @deprecated Use +#create_collection(scope_name, collection_name, settings, options)+ instead
|
280
|
+
#
|
281
|
+
# @return void
|
282
|
+
#
|
283
|
+
# @raise [ArgumentError]
|
284
|
+
# @raise [Error::CollectionExists]
|
285
|
+
# @raise [Error::ScopeNotFound]
|
286
|
+
def create_collection(*args)
|
287
|
+
if args[0].is_a?(CollectionSpec)
|
288
|
+
collection = args[0]
|
289
|
+
options = args[1] || Options::Collection::CreateCollection::DEFAULT
|
290
|
+
settings = CreateCollectionSettings.new(max_expiry: collection.max_expiry, history: collection.history)
|
291
|
+
|
292
|
+
warn "Calling create_collection with a CollectionSpec object has been deprecated, supply scope name, " \
|
293
|
+
"collection name and optionally a CreateCollectionSettings instance"
|
294
|
+
|
295
|
+
@backend.collection_create(@bucket_name, collection.scope_name, collection.name, settings.to_backend, options.to_backend)
|
296
|
+
else
|
297
|
+
scope_name = args[0]
|
298
|
+
collection_name = args[1]
|
299
|
+
settings = args[2] || CreateCollectionSettings::DEFAULT
|
300
|
+
options = args[3] || Options::Collection::CreateCollection::DEFAULT
|
301
|
+
@backend.collection_create(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
# Updates the settings of an existing collection
|
306
|
+
#
|
307
|
+
# @param [String] scope_name the name of the scope the collection is in
|
308
|
+
# @param [String] collection_name the name of the collection to be updated
|
309
|
+
# @param [UpdateCollectionSettings] settings the settings that should be updated
|
310
|
+
#
|
311
|
+
# @raise [ArgumentError]
|
312
|
+
# @raise [Error::CollectionNotFound]
|
313
|
+
# @raise [Error::ScopeNotFound]
|
314
|
+
def update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT,
|
315
|
+
options = Options::Collection::UpdateCollection::DEFAULT)
|
316
|
+
@backend.collection_update(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend)
|
317
|
+
end
|
318
|
+
|
319
|
+
# Removes a collection
|
320
|
+
# @overload drop_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT,
|
321
|
+
# options = Options::Collection::CreateCollection::DEFAULT)
|
322
|
+
# @param [String] scope_name the name of the scope the collection is in
|
323
|
+
# @param [String] collection_name the name of the collection to be removed
|
324
|
+
#
|
325
|
+
# @overload drop_collection(collection, options = Options::Collection::CreateCollection)
|
326
|
+
# @param [CollectionSpec] collection specification of the collection
|
327
|
+
# @param [Options::Collection::CreateCollection] options
|
328
|
+
#
|
329
|
+
# @deprecated Use +#drop_collection(scope_name, collection_name, options)+ instead
|
330
|
+
#
|
331
|
+
# @return void
|
332
|
+
#
|
333
|
+
# @raise [ArgumentError]
|
334
|
+
# @raise [Error::CollectionNotFound]
|
335
|
+
# @raise [Error::ScopeNotFound]
|
336
|
+
def drop_collection(*args)
|
337
|
+
if args[0].is_a?(CollectionSpec)
|
338
|
+
collection = args[0]
|
339
|
+
options = args[1] || Options::Collection::CreateCollection::DEFAULT
|
340
|
+
|
341
|
+
warn "Calling drop_collection with a CollectionSpec object has been deprecated, supply scope name and collection name"
|
342
|
+
|
343
|
+
@backend.collection_drop(@bucket_name, collection.scope_name, collection.name, options.to_backend)
|
344
|
+
else
|
345
|
+
scope_name = args[0]
|
346
|
+
collection_name = args[1]
|
347
|
+
options = args[2] || Options::Collection::CreateCollection::DEFAULT
|
348
|
+
@backend.collection_drop(@bucket_name, scope_name, collection_name, options.to_backend)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
# @deprecated use {CollectionManager#get_all_scopes} instead
|
353
|
+
class GetScopeOptions
|
354
|
+
# @return [Integer] the time in milliseconds allowed for the operation to complete
|
355
|
+
attr_accessor :timeout
|
356
|
+
|
357
|
+
# @yieldparam [GetScopeOptions] self
|
358
|
+
def initialize
|
359
|
+
yield self if block_given?
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
# @api private
|
364
|
+
# TODO: deprecate after 3.2
|
365
|
+
GetAllScopesOptions = ::Couchbase::Management::Options::Collection::GetAllScopes
|
366
|
+
|
367
|
+
# @api private
|
368
|
+
# TODO: deprecate after 3.2
|
369
|
+
CreateScopeOptions = ::Couchbase::Management::Options::Collection::CreateScope
|
370
|
+
|
371
|
+
# @api private
|
372
|
+
# TODO: deprecate after 3.2
|
373
|
+
DropScopeOptions = ::Couchbase::Management::Options::Collection::DropScope
|
374
|
+
|
375
|
+
# @api private
|
376
|
+
# TODO: deprecate after 3.2
|
377
|
+
CreateCollectionOptions = ::Couchbase::Management::Options::Collection::CreateCollection
|
378
|
+
|
379
|
+
# @api private
|
380
|
+
# TODO: deprecate after 3.2
|
381
|
+
DropCollectionOptions = ::Couchbase::Management::Options::Collection::DropCollection
|
382
|
+
end
|
383
|
+
|
384
|
+
class CreateCollectionSettings
|
385
|
+
# @return [Integer, nil] time in seconds of the maximum expiration time for new documents in the collection
|
386
|
+
# (set to +nil+ to use the bucket-level setting, and to +-1+ set it to no-expiry)
|
387
|
+
attr_accessor :max_expiry
|
388
|
+
|
389
|
+
# @return [Boolean, nil] whether history retention override should be enabled in the collection (set to +nil+ to
|
390
|
+
# default to the bucket-level setting)
|
391
|
+
attr_accessor :history
|
392
|
+
|
393
|
+
def initialize(max_expiry: nil, history: nil)
|
394
|
+
@max_expiry = max_expiry
|
395
|
+
@history = history
|
396
|
+
|
397
|
+
yield self if block_given?
|
398
|
+
end
|
399
|
+
|
400
|
+
# @api private
|
401
|
+
def to_backend
|
402
|
+
{
|
403
|
+
max_expiry: @max_expiry,
|
404
|
+
history: @history,
|
405
|
+
}
|
406
|
+
end
|
407
|
+
|
408
|
+
DEFAULT = CreateCollectionSettings.new.freeze
|
409
|
+
end
|
410
|
+
|
411
|
+
class UpdateCollectionSettings
|
412
|
+
# @return [Integer, nil] time in seconds of the maximum expiration time for new documents in the collection
|
413
|
+
# (set to +nil+ to not update it, and to +-1+ set it to no-expiry)
|
414
|
+
attr_accessor :max_expiry
|
415
|
+
|
416
|
+
# @return [Boolean, nil] whether history retention override should be enabled in the collection (set to +nil+ to
|
417
|
+
# not update it)
|
418
|
+
attr_accessor :history
|
419
|
+
|
420
|
+
def initialize(max_expiry: nil, history: nil)
|
421
|
+
@max_expiry = max_expiry
|
422
|
+
@history = history
|
423
|
+
|
424
|
+
yield self if block_given?
|
425
|
+
end
|
426
|
+
|
427
|
+
# @api private
|
428
|
+
def to_backend
|
429
|
+
{
|
430
|
+
max_expiry: @max_expiry,
|
431
|
+
history: @history,
|
432
|
+
}
|
433
|
+
end
|
434
|
+
|
435
|
+
DEFAULT = UpdateCollectionSettings.new.freeze
|
436
|
+
end
|
437
|
+
|
438
|
+
class ScopeSpec
|
439
|
+
# @return [String] name of the scope
|
440
|
+
attr_accessor :name
|
441
|
+
|
442
|
+
# @return [Array<CollectionSpec>] list of collections associated with the scope
|
443
|
+
attr_accessor :collections
|
444
|
+
|
445
|
+
# @yieldparam [ScopeSpec] self
|
446
|
+
def initialize
|
447
|
+
yield self if block_given?
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
class CollectionSpec
|
452
|
+
# @return [String] name of the collection
|
453
|
+
attr_accessor :name
|
454
|
+
|
455
|
+
# @return [String] name of the scope
|
456
|
+
attr_accessor :scope_name
|
457
|
+
|
458
|
+
# @return [Integer] time in seconds of the expiration for new documents in the collection (set to +nil+ to disable it)
|
459
|
+
attr_accessor :max_expiry
|
460
|
+
|
461
|
+
# @return [Boolean, nil] whether history retention is enabled for this collection
|
462
|
+
attr_accessor :history
|
463
|
+
|
464
|
+
# @yieldparam [CollectionSpec] self
|
465
|
+
def initialize
|
466
|
+
yield self if block_given?
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
# Copyright 2023 Couchbase, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "couchbase/management/query_index_manager"
|
16
|
+
require "couchbase/utils/time"
|
17
|
+
require "couchbase/errors"
|
18
|
+
|
19
|
+
module Couchbase
|
20
|
+
module Management
|
21
|
+
class CollectionQueryIndexManager
|
22
|
+
alias inspect to_s
|
23
|
+
|
24
|
+
# @param [Couchbase::Backend] backend
|
25
|
+
# @param [String] bucket_name name of the bucket
|
26
|
+
# @param [String] scope_name name of the scope
|
27
|
+
# @param [String] collection_name name of the collection
|
28
|
+
def initialize(backend, bucket_name, scope_name, collection_name)
|
29
|
+
@backend = backend
|
30
|
+
@bucket_name = bucket_name
|
31
|
+
@scope_name = scope_name
|
32
|
+
@collection_name = collection_name
|
33
|
+
end
|
34
|
+
|
35
|
+
# Fetches all indexes from the server
|
36
|
+
#
|
37
|
+
# @param [Options::Query::GetAllIndexes] options
|
38
|
+
#
|
39
|
+
# @return [Array<QueryIndex>]
|
40
|
+
#
|
41
|
+
# @raise [Error::InvalidArgument]
|
42
|
+
def get_all_indexes(options = Options::Query::GetAllIndexes.new)
|
43
|
+
unless options.scope_name.nil?
|
44
|
+
raise Error::InvalidArgument,
|
45
|
+
"Scope name cannot be set in the options when using the Query Index manager at the collection level"
|
46
|
+
end
|
47
|
+
|
48
|
+
unless options.collection_name.nil?
|
49
|
+
raise Error::InvalidArgument,
|
50
|
+
"Collection name cannot be set in the options when using the Query Index manager at the collection level"
|
51
|
+
end
|
52
|
+
|
53
|
+
res = @backend.collection_query_index_get_all(@bucket_name, @scope_name, @collection_name, options.to_backend)
|
54
|
+
res[:indexes].map do |idx|
|
55
|
+
QueryIndex.new do |index|
|
56
|
+
index.name = idx[:name]
|
57
|
+
index.is_primary = idx[:is_primary]
|
58
|
+
index.type = idx[:type]
|
59
|
+
index.state = idx[:state]
|
60
|
+
index.bucket = idx[:bucket_name]
|
61
|
+
index.scope = idx[:scope_name]
|
62
|
+
index.collection = idx[:collection_name]
|
63
|
+
index.index_key = idx[:index_key]
|
64
|
+
index.condition = idx[:condition]
|
65
|
+
index.partition = idx[:partition]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Creates a new index
|
71
|
+
#
|
72
|
+
# @param [String] index_name name of the index
|
73
|
+
# @param [Array<String>] fields the lists of fields to create th index over
|
74
|
+
# @param [Options::Query::CreateIndex] options
|
75
|
+
#
|
76
|
+
# @return void
|
77
|
+
#
|
78
|
+
# @raise [Error::InvalidArgument]
|
79
|
+
# @raise [Error::IndexExists]
|
80
|
+
def create_index(index_name, fields, options = Options::Query::CreateIndex.new)
|
81
|
+
unless options.scope_name.nil?
|
82
|
+
raise Error::InvalidArgument,
|
83
|
+
"Scope name cannot be set in the options when using the Query Index manager at the collection level"
|
84
|
+
end
|
85
|
+
|
86
|
+
unless options.collection_name.nil?
|
87
|
+
raise Error::InvalidArgument,
|
88
|
+
"Collection name cannot be set in the options when using the Query Index manager at the collection level"
|
89
|
+
end
|
90
|
+
|
91
|
+
@backend.collection_query_index_create(@bucket_name, @scope_name, @collection_name, index_name, fields, options.to_backend)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Creates new primary index
|
95
|
+
#
|
96
|
+
# @param [Options::Query::CreatePrimaryIndex] options
|
97
|
+
#
|
98
|
+
# @return void
|
99
|
+
#
|
100
|
+
# @raise [Error::InvalidArgument]
|
101
|
+
# @raise [Error::IndexExists]
|
102
|
+
def create_primary_index(options = Options::Query::CreatePrimaryIndex.new)
|
103
|
+
unless options.scope_name.nil?
|
104
|
+
raise Error::InvalidArgument,
|
105
|
+
"Scope name cannot be set in the options when using the Query Index manager at the collection level"
|
106
|
+
end
|
107
|
+
|
108
|
+
unless options.collection_name.nil?
|
109
|
+
raise Error::InvalidArgument,
|
110
|
+
"Collection name cannot be set in the options when using the Query Index manager at the collection level"
|
111
|
+
end
|
112
|
+
|
113
|
+
@backend.collection_query_index_create_primary(@bucket_name, @scope_name, @collection_name, options.to_backend)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Drops the index
|
117
|
+
#
|
118
|
+
# @param [String] index_name name of the index
|
119
|
+
# @param [Options::Query::DropIndex] options
|
120
|
+
#
|
121
|
+
# @return void
|
122
|
+
#
|
123
|
+
# @raise [Error::InvalidArgument]
|
124
|
+
# @raise [Error::IndexNotFound]
|
125
|
+
def drop_index(index_name, options = Options::Query::DropIndex.new)
|
126
|
+
unless options.scope_name.nil?
|
127
|
+
raise Error::InvalidArgument,
|
128
|
+
"Scope name cannot be set in the options when using the Query Index manager at the collection level"
|
129
|
+
end
|
130
|
+
|
131
|
+
unless options.collection_name.nil?
|
132
|
+
raise Error::InvalidArgument,
|
133
|
+
"Collection name cannot be set in the options when using the Query Index manager at the collection level"
|
134
|
+
end
|
135
|
+
|
136
|
+
@backend.collection_query_index_drop(@bucket_name, @scope_name, @collection_name, index_name, options.to_backend)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Drops the primary index
|
140
|
+
#
|
141
|
+
# @param [Options::Query::DropPrimaryIndex] options
|
142
|
+
#
|
143
|
+
# @return void
|
144
|
+
#
|
145
|
+
# @raise [Error::InvalidArgument]
|
146
|
+
# @raise [Error::IndexNotFound]
|
147
|
+
def drop_primary_index(options = Options::Query::DropPrimaryIndex.new)
|
148
|
+
unless options.scope_name.nil?
|
149
|
+
raise Error::InvalidArgument,
|
150
|
+
"Scope name cannot be set in the options when using the Query Index manager at the collection level"
|
151
|
+
end
|
152
|
+
|
153
|
+
unless options.collection_name.nil?
|
154
|
+
raise Error::InvalidArgument,
|
155
|
+
"Collection name cannot be set in the options when using the Query Index manager at the collection level"
|
156
|
+
end
|
157
|
+
|
158
|
+
@backend.collection_query_index_drop_primary(@bucket_name, @scope_name, @collection_name, options.to_backend)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Build all indexes which are currently in deferred state
|
162
|
+
#
|
163
|
+
# @param [Options::Query::BuildDeferredIndexes] options
|
164
|
+
#
|
165
|
+
# @return void
|
166
|
+
#
|
167
|
+
# @raise [Error::InvalidArgument]
|
168
|
+
def build_deferred_indexes(options = Options::Query::BuildDeferredIndexes.new)
|
169
|
+
unless options.scope_name.nil?
|
170
|
+
raise Error::InvalidArgument,
|
171
|
+
"Scope name cannot be set in the options when using the Query Index manager at the collection level"
|
172
|
+
end
|
173
|
+
|
174
|
+
unless options.collection_name.nil?
|
175
|
+
raise Error::InvalidArgument,
|
176
|
+
"Collection name cannot be set in the options when using the Query Index manager at the collection level"
|
177
|
+
end
|
178
|
+
|
179
|
+
@backend.collection_query_index_build_deferred(@bucket_name, @scope_name, @collection_name, options.to_backend)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Polls indexes until they are online
|
183
|
+
#
|
184
|
+
# @param [Array<String>] index_names names of the indexes to watch
|
185
|
+
# @param [Integer, #in_milliseconds] timeout the time in milliseconds allowed for the operation to complete
|
186
|
+
# @param [Options::Query::WatchIndexes] options
|
187
|
+
#
|
188
|
+
# @raise [Error::InvalidArgument]
|
189
|
+
# @raise [Error::IndexNotFound]
|
190
|
+
def watch_indexes(index_names, timeout, options = Options::Query::WatchIndexes.new)
|
191
|
+
unless options.scope_name.nil?
|
192
|
+
raise Error::InvalidArgument,
|
193
|
+
"Scope name cannot be set in the options when using the Query Index manager at the collection level"
|
194
|
+
end
|
195
|
+
|
196
|
+
unless options.collection_name.nil?
|
197
|
+
raise Error::InvalidArgument,
|
198
|
+
"Collection name cannot be set in the options when using the Query Index manager at the collection level"
|
199
|
+
end
|
200
|
+
|
201
|
+
index_names.append("#primary") if options.watch_primary
|
202
|
+
|
203
|
+
interval_millis = 50
|
204
|
+
deadline = Time.now + (Utils::Time.extract_duration(timeout) * 0.001)
|
205
|
+
while Time.now <= deadline
|
206
|
+
get_all_opts = Options::Query::GetAllIndexes.new(timeout: ((deadline - Time.now) * 1000).round)
|
207
|
+
indexes = get_all_indexes(get_all_opts).select { |idx| index_names.include? idx.name }
|
208
|
+
indexes_not_found = index_names - indexes.map(&:name)
|
209
|
+
raise Error::IndexNotFound, "Failed to find the indexes: #{indexes_not_found.join(', ')}" unless indexes_not_found.empty?
|
210
|
+
|
211
|
+
all_online = indexes.all? { |idx| idx.state == :online }
|
212
|
+
return if all_online
|
213
|
+
|
214
|
+
sleep(interval_millis / 1000)
|
215
|
+
interval_millis += 500
|
216
|
+
interval_millis = 1000 if interval_millis > 1000
|
217
|
+
end
|
218
|
+
raise Error::UnambiguousTimeout, "Failed to find all indexes online within the allotted time"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|