couchbase 3.5.3-arm64-darwin
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 +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,401 @@
|
|
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/json_transcoder"
|
20
|
+
require "couchbase/raw_string_transcoder"
|
21
|
+
require "couchbase/raw_json_transcoder"
|
22
|
+
require "couchbase/raw_binary_transcoder"
|
23
|
+
require "couchbase/subdoc"
|
24
|
+
require "couchbase/mutation_state"
|
25
|
+
|
26
|
+
module Couchbase
|
27
|
+
class Collection
|
28
|
+
class GetResult
|
29
|
+
extend Gem::Deprecate
|
30
|
+
|
31
|
+
# @return [Integer] holds the CAS value of the fetched document
|
32
|
+
attr_accessor :cas
|
33
|
+
|
34
|
+
# @return [Integer] the expiration if fetched and present
|
35
|
+
attr_writer :expiry
|
36
|
+
|
37
|
+
# @return [Error::CouchbaseError, nil] error associated with the result, or nil (used in {Collection#get_multi})
|
38
|
+
attr_accessor :error
|
39
|
+
|
40
|
+
# @return [String, nil] identifier of the document (used for {Collection#get_multi})
|
41
|
+
attr_accessor :id
|
42
|
+
|
43
|
+
# @return [Boolean] true if error was not associated with the result (useful for multi-operations)
|
44
|
+
def success?
|
45
|
+
!error
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [String] The encoded content when loading the document
|
49
|
+
# @api private
|
50
|
+
attr_accessor :encoded
|
51
|
+
|
52
|
+
# Decodes the content of the document using given (or default transcoder)
|
53
|
+
#
|
54
|
+
# @param [JsonTranscoder] transcoder custom transcoder
|
55
|
+
#
|
56
|
+
# @return [Object]
|
57
|
+
def content(transcoder = self.transcoder)
|
58
|
+
transcoder ? transcoder.decode(@encoded, @flags) : @encoded
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Time] time when the document will expire
|
62
|
+
def expiry_time
|
63
|
+
Time.at(@expiry) if @expiry
|
64
|
+
end
|
65
|
+
|
66
|
+
# @yieldparam [GetResult] self
|
67
|
+
def initialize
|
68
|
+
@expiry = nil
|
69
|
+
@error = nil
|
70
|
+
@id = nil
|
71
|
+
yield self if block_given?
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Integer] The flags from the operation
|
75
|
+
# @api private
|
76
|
+
attr_accessor :flags
|
77
|
+
|
78
|
+
# @return [JsonTranscoder] The default transcoder which should be used
|
79
|
+
attr_accessor :transcoder
|
80
|
+
|
81
|
+
# @deprecated Use {#expiry_time}
|
82
|
+
# @return [Integer] the expiration if fetched and present
|
83
|
+
def expiry # rubocop:disable Style/TrivialAccessors will be removed in next major release
|
84
|
+
@expiry
|
85
|
+
end
|
86
|
+
|
87
|
+
deprecate :expiry, :expiry_time, 2021, 1
|
88
|
+
end
|
89
|
+
|
90
|
+
class GetReplicaResult < GetResult
|
91
|
+
# @return [Boolean] true if this result came from a replica
|
92
|
+
attr_accessor :is_replica
|
93
|
+
alias replica? is_replica
|
94
|
+
end
|
95
|
+
|
96
|
+
class ExistsResult
|
97
|
+
# @return [Integer] holds the CAS value of the fetched document
|
98
|
+
attr_accessor :cas
|
99
|
+
|
100
|
+
# @return [Boolean] true if the document was deleted
|
101
|
+
attr_accessor :deleted
|
102
|
+
|
103
|
+
# @return [Boolean] true if the document exists
|
104
|
+
attr_accessor :exists
|
105
|
+
alias exists? exists
|
106
|
+
|
107
|
+
# @yieldparam [ExistsResult]
|
108
|
+
def initialize
|
109
|
+
yield self if block_given?
|
110
|
+
end
|
111
|
+
|
112
|
+
# @return [Integer] the expiration if fetched and present
|
113
|
+
attr_writer :expiry
|
114
|
+
|
115
|
+
# @return [Time] time when the document will expire
|
116
|
+
def expiry_time
|
117
|
+
Time.at(@expiry) if @expiry
|
118
|
+
end
|
119
|
+
|
120
|
+
# @api private
|
121
|
+
# @return [Integer] flags
|
122
|
+
attr_accessor :flags
|
123
|
+
|
124
|
+
# @api private
|
125
|
+
# @return [Integer] sequence_number
|
126
|
+
attr_accessor :sequence_number
|
127
|
+
|
128
|
+
# @api private
|
129
|
+
# @return [Integer] datatype
|
130
|
+
attr_accessor :datatype
|
131
|
+
end
|
132
|
+
|
133
|
+
class MutationResult
|
134
|
+
# @return [Integer] holds the CAS value of the document after the mutation
|
135
|
+
attr_accessor :cas
|
136
|
+
|
137
|
+
# @return [MutationToken] if returned, holds the mutation token of the document after the mutation
|
138
|
+
attr_accessor :mutation_token
|
139
|
+
|
140
|
+
# @return [Error::CouchbaseError, nil] error or nil (used in multi-operations like {Collection#upsert_multi},
|
141
|
+
# {Collection#remove_multi})
|
142
|
+
attr_accessor :error
|
143
|
+
|
144
|
+
# @return [String, nil] identifier of the document (used in multi-operations like {Collection#upsert_multi},
|
145
|
+
# {Collection#remove_multi})
|
146
|
+
attr_accessor :id
|
147
|
+
|
148
|
+
# @return [Boolean] true if error was not associated with the result (useful for multi-operations)
|
149
|
+
def success?
|
150
|
+
!error
|
151
|
+
end
|
152
|
+
|
153
|
+
# @yieldparam [MutationResult] self
|
154
|
+
def initialize
|
155
|
+
@error = nil
|
156
|
+
@id = nil
|
157
|
+
yield self if block_given?
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class LookupInResult
|
162
|
+
# @return [Integer] holds the CAS value of the fetched document
|
163
|
+
attr_accessor :cas
|
164
|
+
|
165
|
+
# Decodes the content at the given index (or path)
|
166
|
+
#
|
167
|
+
# @param [Integer, String] path_or_index the index (or path) of the subdocument value to decode
|
168
|
+
#
|
169
|
+
# @return [Object] the decoded
|
170
|
+
def content(path_or_index, transcoder = self.transcoder)
|
171
|
+
field = get_field_at_index(path_or_index)
|
172
|
+
|
173
|
+
raise field.error unless field.error.nil?
|
174
|
+
|
175
|
+
transcoder.decode(field.value, :json)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Allows to check if a value at the given index exists
|
179
|
+
#
|
180
|
+
# @param [Integer, String] path_or_index the index (or path) of the subdocument value to check
|
181
|
+
#
|
182
|
+
# @return [Boolean] true if a value is present at the index, false otherwise
|
183
|
+
def exists?(path_or_index)
|
184
|
+
field =
|
185
|
+
case path_or_index
|
186
|
+
when String
|
187
|
+
encoded.find { |f| f.path == path_or_index }
|
188
|
+
else
|
189
|
+
return false unless path_or_index >= 0 && path_or_index < encoded.size
|
190
|
+
|
191
|
+
encoded[path_or_index]
|
192
|
+
end
|
193
|
+
return false unless field
|
194
|
+
|
195
|
+
raise field.error unless field.error.nil? || field.error.is_a?(Error::PathNotFound)
|
196
|
+
|
197
|
+
field.exists
|
198
|
+
end
|
199
|
+
|
200
|
+
# @return [Array<SubDocumentField>] holds the encoded subdocument responses
|
201
|
+
attr_accessor :encoded
|
202
|
+
|
203
|
+
# @yieldparam [LookupInResult] self
|
204
|
+
def initialize
|
205
|
+
@deleted = false
|
206
|
+
yield self if block_given?
|
207
|
+
end
|
208
|
+
|
209
|
+
# @return [JsonTranscoder] The default transcoder which should be used
|
210
|
+
attr_accessor :transcoder
|
211
|
+
|
212
|
+
# @api private
|
213
|
+
#
|
214
|
+
# @see MutateInOptions#create_as_deleted
|
215
|
+
#
|
216
|
+
# @return [Boolean] true if the document is a tombstone (created in deleted state)
|
217
|
+
def deleted?
|
218
|
+
@deleted
|
219
|
+
end
|
220
|
+
|
221
|
+
# @api private
|
222
|
+
attr_accessor :deleted
|
223
|
+
|
224
|
+
private
|
225
|
+
|
226
|
+
def get_field_at_index(path_or_index)
|
227
|
+
case path_or_index
|
228
|
+
when String
|
229
|
+
encoded.find { |field| field.path == path_or_index } or raise Error::PathInvalid, "Path is not found: #{path_or_index}"
|
230
|
+
else
|
231
|
+
raise Error::PathInvalid, "Index is out of bounds: #{path_or_index}" unless path_or_index >= 0 && path_or_index < encoded.size
|
232
|
+
|
233
|
+
encoded[path_or_index]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
class LookupInReplicaResult < LookupInResult
|
239
|
+
# @return [Boolean] true if the document was read from a replica node
|
240
|
+
attr_accessor :is_replica
|
241
|
+
alias replica? is_replica
|
242
|
+
|
243
|
+
# @yieldparam [LookupInReplicaResult] self
|
244
|
+
def initialize
|
245
|
+
super
|
246
|
+
yield self if block_given?
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
class MutateInResult < MutationResult
|
251
|
+
# Decodes the content at the given index
|
252
|
+
#
|
253
|
+
# @param [Integer, String] path_or_index the index (or path) of the subdocument value to decode
|
254
|
+
#
|
255
|
+
# @return [Object] the decoded
|
256
|
+
def content(path_or_index, transcoder = self.transcoder)
|
257
|
+
field = get_field_at_index(path_or_index)
|
258
|
+
transcoder.decode(field.value, :json)
|
259
|
+
end
|
260
|
+
|
261
|
+
# @yieldparam [MutateInResult] self
|
262
|
+
def initialize
|
263
|
+
super
|
264
|
+
yield self if block_given?
|
265
|
+
end
|
266
|
+
|
267
|
+
# @return [Array<SubDocumentField>] holds the encoded subdocument responses
|
268
|
+
# @api private
|
269
|
+
attr_accessor :encoded
|
270
|
+
|
271
|
+
# @return [JsonTranscoder] The default transcoder which should be used
|
272
|
+
attr_accessor :transcoder
|
273
|
+
|
274
|
+
# @api private
|
275
|
+
#
|
276
|
+
# @see MutateInOptions#create_as_deleted
|
277
|
+
#
|
278
|
+
# @return [Boolean] true if the document is a tombstone (created in deleted state)
|
279
|
+
def deleted?
|
280
|
+
@deleted
|
281
|
+
end
|
282
|
+
|
283
|
+
# @api private
|
284
|
+
attr_accessor :deleted
|
285
|
+
|
286
|
+
private
|
287
|
+
|
288
|
+
def get_field_at_index(path_or_index)
|
289
|
+
case path_or_index
|
290
|
+
when String
|
291
|
+
encoded.find { |field| field.path == path_or_index } or raise Error::PathInvalid, "Path is not found: #{path_or_index}"
|
292
|
+
else
|
293
|
+
raise Error::PathInvalid, "Index is out of bounds: #{path_or_index}" unless path_or_index >= 0 && path_or_index < encoded.size
|
294
|
+
|
295
|
+
encoded[path_or_index]
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
# @api private
|
301
|
+
class SubDocumentField
|
302
|
+
# @return [Boolean] true if the path exists in the document
|
303
|
+
attr_accessor :exists
|
304
|
+
|
305
|
+
# @return [String] value
|
306
|
+
attr_accessor :value
|
307
|
+
|
308
|
+
# @return [Integer] index
|
309
|
+
attr_accessor :index
|
310
|
+
|
311
|
+
# @return [String] path
|
312
|
+
attr_accessor :path
|
313
|
+
|
314
|
+
# @return [CouchbaseError] error
|
315
|
+
attr_accessor :error
|
316
|
+
|
317
|
+
# @yieldparam [SubDocumentField] self
|
318
|
+
def initialize
|
319
|
+
yield self if block_given?
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
class ScanResult
|
324
|
+
# @return [String] identifier of the document
|
325
|
+
attr_accessor :id
|
326
|
+
|
327
|
+
# @return [Boolean] whether only ids are returned from this scan
|
328
|
+
attr_accessor :id_only
|
329
|
+
|
330
|
+
# @return [Integer, nil] holds the CAS value of the fetched document
|
331
|
+
attr_accessor :cas
|
332
|
+
|
333
|
+
# @return [Integer, nil] the expiration if fetched and present
|
334
|
+
attr_accessor :expiry
|
335
|
+
|
336
|
+
# @return [JsonTranscoder, RawBinaryTranscoder, RawJsonTranscoder, RawStringTranscoder, #decode] The default
|
337
|
+
# transcoder which should be used
|
338
|
+
attr_accessor :transcoder
|
339
|
+
|
340
|
+
def initialize(id:, id_only:, cas: nil, expiry: nil, encoded: nil, flags: nil, transcoder: JsonTranscoder.new)
|
341
|
+
@id = id
|
342
|
+
@id_only = id_only
|
343
|
+
@cas = cas
|
344
|
+
@expiry = expiry
|
345
|
+
@encoded = encoded
|
346
|
+
@flags = flags
|
347
|
+
@transcoder = transcoder
|
348
|
+
|
349
|
+
yield self if block_given?
|
350
|
+
end
|
351
|
+
|
352
|
+
# Decodes the content of the document using given (or default transcoder)
|
353
|
+
#
|
354
|
+
# @param [JsonTranscoder, RawJsonTranscoder, RawBinaryTranscoder, RawStringTranscoder] transcoder custom transcoder
|
355
|
+
#
|
356
|
+
# @return [Object, nil]
|
357
|
+
def content(transcoder = self.transcoder)
|
358
|
+
return nil if @encoded.nil?
|
359
|
+
|
360
|
+
transcoder ? transcoder.decode(@encoded, @flags) : @encoded
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
class ScanResults
|
365
|
+
include Enumerable
|
366
|
+
|
367
|
+
def initialize(core_scan_result:, transcoder:)
|
368
|
+
@core_scan_result = core_scan_result
|
369
|
+
@transcoder = transcoder
|
370
|
+
end
|
371
|
+
|
372
|
+
def each
|
373
|
+
return enum_for(:each) unless block_given?
|
374
|
+
|
375
|
+
loop do
|
376
|
+
resp = @core_scan_result.next_item
|
377
|
+
|
378
|
+
break if resp.nil?
|
379
|
+
|
380
|
+
if resp[:id_only]
|
381
|
+
yield ScanResult.new(
|
382
|
+
id: resp[:id],
|
383
|
+
id_only: resp[:id_only],
|
384
|
+
transcoder: @transcoder
|
385
|
+
)
|
386
|
+
else
|
387
|
+
yield ScanResult.new(
|
388
|
+
id: resp[:id],
|
389
|
+
id_only: resp[:id_only],
|
390
|
+
cas: resp[:cas],
|
391
|
+
expiry: resp[:expiry],
|
392
|
+
encoded: resp[:encoded],
|
393
|
+
flags: resp[:flags],
|
394
|
+
transcoder: @transcoder
|
395
|
+
)
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020-2022 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
|
+
module Couchbase
|
18
|
+
module ConfigProfiles
|
19
|
+
class Profiles
|
20
|
+
attr_reader :profiles
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@profiles = {}
|
24
|
+
register_profile("wan_development", DevelopmentProfile.new)
|
25
|
+
end
|
26
|
+
|
27
|
+
def register_profile(name, profile)
|
28
|
+
@profiles[name] = profile
|
29
|
+
end
|
30
|
+
|
31
|
+
def apply(profile_name, options)
|
32
|
+
raise ArgumentError, "#{profile_name} is not a registered profile" unless @profiles.key?(profile_name)
|
33
|
+
|
34
|
+
@profiles[profile_name].apply(options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Profile
|
39
|
+
def apply(options); end
|
40
|
+
end
|
41
|
+
|
42
|
+
class DevelopmentProfile < Profile
|
43
|
+
def apply(options)
|
44
|
+
options.key_value_timeout = 20_000
|
45
|
+
# TODO: Add `options.key_value_durable_timeout = 20_000` when key_value_durable_timeout is added to Options::Cluster
|
46
|
+
options.connect_timeout = 20_000
|
47
|
+
options.view_timeout = 120_000
|
48
|
+
options.query_timeout = 120_000
|
49
|
+
options.analytics_timeout = 120_000
|
50
|
+
options.search_timeout = 120_000
|
51
|
+
options.management_timeout = 120_000
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
KNOWN_PROFILES = Profiles.new
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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 "yaml"
|
18
|
+
require "erb"
|
19
|
+
|
20
|
+
module Couchbase
|
21
|
+
class Configuration
|
22
|
+
attr_accessor :connection_string
|
23
|
+
attr_accessor :username
|
24
|
+
attr_accessor :password
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@connection_string = "couchbase://localhost"
|
28
|
+
end
|
29
|
+
|
30
|
+
def load!(path, environment = default_environment_name)
|
31
|
+
settings = load_yaml(path, environment)
|
32
|
+
load_configuration(settings)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def load_configuration(settings)
|
38
|
+
@connection_string = settings[:connection_string] || settings["connection_string"]
|
39
|
+
@username = settings[:username] || settings["username"]
|
40
|
+
@password = settings[:password] || settings["password"]
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_yaml(path, environment)
|
44
|
+
file_content = ERB.new(File.read(path)).result
|
45
|
+
YAML.safe_load(file_content, aliases: :default)[environment]
|
46
|
+
end
|
47
|
+
|
48
|
+
def default_environment_name
|
49
|
+
if defined?(::Rails)
|
50
|
+
::Rails.env
|
51
|
+
elsif defined?(::Sinatra)
|
52
|
+
::Sinatra::Base.environment.to_s
|
53
|
+
else
|
54
|
+
ENV.fetch("RACK_ENV", nil) || ENV.fetch("COUCHBASE_ENV", nil) or raise ::Couchbase::Error::NoEnvironment
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,160 @@
|
|
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 "couchbase/collection"
|
18
|
+
require "couchbase/errors"
|
19
|
+
require "couchbase/options"
|
20
|
+
|
21
|
+
module Couchbase
|
22
|
+
module Datastructures
|
23
|
+
# A {CouchbaseList} is implements +Enumerable+ interface and backed by {Collection} document (more specifically
|
24
|
+
# a JSON array).
|
25
|
+
#
|
26
|
+
# Note that as such, a {CouchbaseList} is restricted to the types that JSON array can contain.
|
27
|
+
class CouchbaseList
|
28
|
+
include Enumerable
|
29
|
+
|
30
|
+
# Create a new List, backed by the document identified by +id+ in +collection+.
|
31
|
+
#
|
32
|
+
# @param [String] id the id of the document to back the list.
|
33
|
+
# @param [Collection] collection the Couchbase collection through which to interact with the document.
|
34
|
+
# @param [Options::CouchbaseList] options customization of the datastructure
|
35
|
+
def initialize(id, collection, options = Options::CouchbaseList.new)
|
36
|
+
@id = id
|
37
|
+
@collection = collection
|
38
|
+
@options = options
|
39
|
+
@cas = 0
|
40
|
+
end
|
41
|
+
|
42
|
+
# Calls the given block once for each element in the list, passing that element as a parameter.
|
43
|
+
#
|
44
|
+
# @yieldparam [Object] item
|
45
|
+
#
|
46
|
+
# @return [CouchbaseList, Enumerable]
|
47
|
+
def each(&)
|
48
|
+
if block_given?
|
49
|
+
begin
|
50
|
+
result = @collection.get(@id, @options.get_options)
|
51
|
+
current = result.content
|
52
|
+
@cas = result.cas
|
53
|
+
rescue Error::DocumentNotFound
|
54
|
+
current = []
|
55
|
+
@cas = 0
|
56
|
+
end
|
57
|
+
current.each(&)
|
58
|
+
self
|
59
|
+
else
|
60
|
+
enum_for(:each)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Integer] returns the number of elements in the list.
|
65
|
+
def length
|
66
|
+
result = @collection.lookup_in(@id, [
|
67
|
+
LookupInSpec.count(""),
|
68
|
+
], @options.lookup_in_options)
|
69
|
+
result.content(0)
|
70
|
+
rescue Error::DocumentNotFound
|
71
|
+
0
|
72
|
+
end
|
73
|
+
|
74
|
+
alias size length
|
75
|
+
|
76
|
+
# @return [Boolean] returns true if list is empty
|
77
|
+
def empty?
|
78
|
+
size.zero?
|
79
|
+
end
|
80
|
+
|
81
|
+
# Appends the given object(s) on to the end of this error. This expression returns the array itself, so several
|
82
|
+
# appends may be chained together.
|
83
|
+
#
|
84
|
+
# @param [Object...] obj object(s) to append
|
85
|
+
# @return [CouchbaseList]
|
86
|
+
def push(*obj)
|
87
|
+
@collection.mutate_in(@id, [
|
88
|
+
MutateInSpec.array_append("", obj),
|
89
|
+
], @options.mutate_in_options)
|
90
|
+
self
|
91
|
+
end
|
92
|
+
|
93
|
+
alias append push
|
94
|
+
|
95
|
+
# Prepends objects to the front of the list, moving other elements upwards
|
96
|
+
#
|
97
|
+
# @param [Object...] obj object(s) to prepend
|
98
|
+
# @return [CouchbaseList]
|
99
|
+
def unshift(*obj)
|
100
|
+
@collection.mutate_in(@id, [
|
101
|
+
MutateInSpec.array_prepend("", obj),
|
102
|
+
], @options.mutate_in_options)
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
alias prepend unshift
|
107
|
+
|
108
|
+
# Inserts the given values before the element with the given +index+.
|
109
|
+
#
|
110
|
+
# @param [Integer] index
|
111
|
+
# @param [Object...] obj object(s) to insert
|
112
|
+
# @return [CouchbaseList]
|
113
|
+
def insert(index, *obj)
|
114
|
+
@collection.mutate_in(@id, [
|
115
|
+
MutateInSpec.array_insert("[#{index.to_i}]", obj),
|
116
|
+
])
|
117
|
+
self
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns the element at +index+. A negative index counts from the end. Returns +nil+ if the index is out of range.
|
121
|
+
#
|
122
|
+
# @param [Integer] index
|
123
|
+
# @return [Object, nil]
|
124
|
+
def at(index)
|
125
|
+
result = @collection.lookup_in(@id, [
|
126
|
+
LookupInSpec.get("[#{index.to_i}]"),
|
127
|
+
], @options.lookup_in_options)
|
128
|
+
result.exists?(0) ? result.content(0) : nil
|
129
|
+
rescue Error::DocumentNotFound
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
|
133
|
+
alias [] at
|
134
|
+
|
135
|
+
# Deletes the element at the specified +index+, returning that element, or nil
|
136
|
+
#
|
137
|
+
# @param [Integer] index
|
138
|
+
# @return [CouchbaseList]
|
139
|
+
def delete_at(index)
|
140
|
+
@collection.mutate_in(@id, [
|
141
|
+
MutateInSpec.remove("[#{index.to_i}]"),
|
142
|
+
])
|
143
|
+
self
|
144
|
+
rescue Error::DocumentNotFound
|
145
|
+
self
|
146
|
+
end
|
147
|
+
|
148
|
+
# Removes all elements from the list
|
149
|
+
def clear
|
150
|
+
@collection.remove(@id, @options.remove_options)
|
151
|
+
nil
|
152
|
+
rescue Error::DocumentNotFound
|
153
|
+
nil
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# @api private
|
158
|
+
CouchbaseListOptions = ::Couchbase::Options::CouchbaseList
|
159
|
+
end
|
160
|
+
end
|