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