couchbase 3.4.0-arm64-darwin-20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +202 -0
  3. data/README.md +154 -0
  4. data/ext/extconf.rb +0 -0
  5. data/lib/active_support/cache/couchbase_store.rb +339 -0
  6. data/lib/couchbase/analytics_options.rb +107 -0
  7. data/lib/couchbase/authenticator.rb +65 -0
  8. data/lib/couchbase/binary_collection.rb +128 -0
  9. data/lib/couchbase/binary_collection_options.rb +24 -0
  10. data/lib/couchbase/bucket.rb +144 -0
  11. data/lib/couchbase/cluster.rb +439 -0
  12. data/lib/couchbase/cluster_registry.rb +44 -0
  13. data/lib/couchbase/collection.rb +589 -0
  14. data/lib/couchbase/collection_options.rb +300 -0
  15. data/lib/couchbase/config_profiles.rb +55 -0
  16. data/lib/couchbase/configuration.rb +57 -0
  17. data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
  18. data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
  19. data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
  20. data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
  21. data/lib/couchbase/datastructures.rb +24 -0
  22. data/lib/couchbase/diagnostics.rb +181 -0
  23. data/lib/couchbase/errors.rb +351 -0
  24. data/lib/couchbase/json_transcoder.rb +32 -0
  25. data/lib/couchbase/libcouchbase.bundle +0 -0
  26. data/lib/couchbase/logger.rb +85 -0
  27. data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
  28. data/lib/couchbase/management/bucket_manager.rb +436 -0
  29. data/lib/couchbase/management/collection_manager.rb +321 -0
  30. data/lib/couchbase/management/query_index_manager.rb +520 -0
  31. data/lib/couchbase/management/search_index_manager.rb +408 -0
  32. data/lib/couchbase/management/user_manager.rb +468 -0
  33. data/lib/couchbase/management/view_index_manager.rb +237 -0
  34. data/lib/couchbase/management.rb +27 -0
  35. data/lib/couchbase/mutation_state.rb +63 -0
  36. data/lib/couchbase/options.rb +2580 -0
  37. data/lib/couchbase/query_options.rb +120 -0
  38. data/lib/couchbase/railtie.rb +45 -0
  39. data/lib/couchbase/scope.rb +232 -0
  40. data/lib/couchbase/search_options.rb +1570 -0
  41. data/lib/couchbase/subdoc.rb +290 -0
  42. data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
  43. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  44. data/lib/couchbase/utils/time.rb +56 -0
  45. data/lib/couchbase/utils.rb +21 -0
  46. data/lib/couchbase/version.rb +23 -0
  47. data/lib/couchbase/view_options.rb +65 -0
  48. data/lib/couchbase.rb +20 -0
  49. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  50. metadata +101 -0
@@ -0,0 +1,408 @@
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 "couchbase/errors"
16
+
17
+ module Couchbase
18
+ module Management
19
+ class SearchIndexManager
20
+ alias inspect to_s
21
+
22
+ # @param [Couchbase::Backend] backend
23
+ def initialize(backend)
24
+ @backend = backend
25
+ end
26
+
27
+ # Fetches an index from the server if it exists
28
+ #
29
+ # @param [String] index_name name of the index
30
+ # @param [GetIndexOptions] options
31
+ #
32
+ # @return [SearchIndex]
33
+ #
34
+ # @raise [ArgumentError]
35
+ # @raise [Error::IndexNotFound]
36
+ def get_index(index_name, options = GetIndexOptions.new)
37
+ res = @backend.search_index_get(index_name, options.timeout)
38
+ extract_search_index(res)
39
+ end
40
+
41
+ # Fetches all indexes from the server
42
+ #
43
+ # @param [GetAllIndexesOptions] options
44
+ #
45
+ # @return [Array<SearchIndex>]
46
+ def get_all_indexes(options = GetAllIndexesOptions.new)
47
+ res = @backend.search_index_get_all(options.timeout)
48
+ res[:indexes].map { |idx| extract_search_index(idx) }
49
+ end
50
+
51
+ # Creates or updates the index
52
+ #
53
+ # @param [SearchIndex] index_definition the index definition
54
+ # @param [UpsertIndexOptions] options
55
+ #
56
+ # @return void
57
+ #
58
+ # @raise [ArgumentError] if name, type or source_type is empty
59
+ def upsert_index(index_definition, options = UpsertIndexOptions.new)
60
+ @backend.search_index_upsert(
61
+ {
62
+ name: index_definition.name,
63
+ type: index_definition.type,
64
+ uuid: index_definition.uuid,
65
+ params: (JSON.generate(index_definition.params) if index_definition.params),
66
+ source_name: index_definition.source_name,
67
+ source_type: index_definition.source_type,
68
+ source_uuid: index_definition.source_uuid,
69
+ source_params: (JSON.generate(index_definition.source_params) if index_definition.source_params),
70
+ plan_params: (JSON.generate(index_definition.plan_params) if index_definition.plan_params),
71
+ }, options.timeout
72
+ )
73
+ end
74
+
75
+ # Drops the index
76
+ #
77
+ # @param [String] index_name name of the index
78
+ # @param [DropIndexOptions] options
79
+ #
80
+ # @return void
81
+ #
82
+ # @raise [ArgumentError]
83
+ # @raise [Error::IndexNotFound]
84
+ def drop_index(index_name, options = DropIndexOptions.new)
85
+ @backend.search_index_drop(index_name, options.timeout)
86
+ end
87
+
88
+ # Retrieves the number of documents that have been indexed for an index
89
+ #
90
+ # @param [String] index_name name of the index
91
+ # @param [GetIndexedDocumentsCountOptions] options
92
+ #
93
+ # @return [Integer]
94
+ #
95
+ # @raise [ArgumentError]
96
+ # @raise [Error::IndexNotFound]
97
+ def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOptions.new)
98
+ res = @backend.search_index_get_documents_count(index_name, options.timeout)
99
+ res[:count]
100
+ end
101
+
102
+ # Retrieves metrics, timings and counters for a given index
103
+ #
104
+ # @api uncommitted
105
+ #
106
+ # @param [String] index_name name of the index
107
+ # @param [GetIndexStatsOptions] options
108
+ #
109
+ # @return [Integer]
110
+ #
111
+ # @raise [ArgumentError]
112
+ # @raise [Error::IndexNotFound]
113
+ def get_index_stats(index_name, options = GetIndexStatsOptions.new)
114
+ res = @backend.search_index_get_stats(index_name, options.timeout)
115
+ JSON.parse(res)
116
+ end
117
+
118
+ # Retrieves statistics on search service. Information is provided on documents, partition indexes, mutations,
119
+ # compactions, queries, and more.
120
+ #
121
+ # @api uncommitted
122
+ #
123
+ # @param [GetIndexStatsOptions] options
124
+ #
125
+ # @return [Integer]
126
+ #
127
+ # @raise [ArgumentError]
128
+ def get_stats(options = GetIndexStatsOptions.new)
129
+ res = @backend.search_get_stats(options.timeout)
130
+ JSON.parse(res)
131
+ end
132
+
133
+ # Pauses updates and maintenance for the index
134
+ #
135
+ # @param [String] index_name name of the index
136
+ # @param [PauseIngestOptions] options
137
+ #
138
+ # @return void
139
+ #
140
+ # @raise [ArgumentError]
141
+ # @raise [Error::IndexNotFound]
142
+ def pause_ingest(index_name, options = PauseIngestOptions.new)
143
+ @backend.search_index_pause_ingest(index_name, options.timeout)
144
+ end
145
+
146
+ # Resumes updates and maintenance for an index
147
+ #
148
+ # @param [String] index_name name of the index
149
+ # @param [ResumeIngestOptions] options
150
+ #
151
+ # @return void
152
+ #
153
+ # @raise [ArgumentError]
154
+ # @raise [Error::IndexNotFound]
155
+ def resume_ingest(index_name, options = ResumeIngestOptions.new)
156
+ @backend.search_index_resume_ingest(index_name, options.timeout)
157
+ end
158
+
159
+ # Allows querying against the index
160
+ #
161
+ # @param [String] index_name name of the index
162
+ # @param [AllowQueryingOptions] options
163
+ #
164
+ # @return void
165
+ #
166
+ # @raise [ArgumentError]
167
+ # @raise [Error::IndexNotFound]
168
+ def allow_querying(index_name, options = AllowQueryingOptions.new)
169
+ @backend.search_index_allow_querying(index_name, options.timeout)
170
+ end
171
+
172
+ # Disallows querying against the index
173
+ #
174
+ # @param [String] index_name name of the index
175
+ # @param [DisallowQueryingOptions] options
176
+ #
177
+ # @return void
178
+ #
179
+ # @raise [ArgumentError]
180
+ # @raise [Error::IndexNotFound]
181
+ def disallow_querying(index_name, options = DisallowQueryingOptions.new)
182
+ @backend.search_index_disallow_querying(index_name, options.timeout)
183
+ end
184
+
185
+ # Freeze the assignment of index partitions to nodes
186
+ #
187
+ # @param [String] index_name name of the index
188
+ # @param [FreezePlanOptions] options
189
+ #
190
+ # @return void
191
+ #
192
+ # @raise [ArgumentError]
193
+ # @raise [Error::IndexNotFound]
194
+ def freeze_plan(index_name, options = FreezePlanOptions.new)
195
+ @backend.search_index_freeze_plan(index_name, options.timeout)
196
+ end
197
+
198
+ # Unfreeze the assignment of index partitions to nodes
199
+ #
200
+ # @param [String] index_name name of the index
201
+ # @param [UnfreezePlanOptions] options
202
+ #
203
+ # @return void
204
+ #
205
+ # @raise [ArgumentError]
206
+ # @raise [Error::IndexNotFound]
207
+ def unfreeze_plan(index_name, options = UnfreezePlanOptions.new)
208
+ @backend.search_index_unfreeze_plan(index_name, options.timeout)
209
+ end
210
+
211
+ # Allows to see how a document is analyzed against a specific index
212
+ #
213
+ # @param [String] index_name name of the index
214
+ # @param [Hash] document the document to be analyzed
215
+ #
216
+ # @return [Array<Hash>]
217
+ #
218
+ # @raise [ArgumentError]
219
+ # @raise [Error::IndexNotFound]
220
+ def analyze_document(index_name, document, options = AnalyzeDocumentOptions.new)
221
+ res = @backend.search_index_analyze_document(index_name, JSON.generate(document), options.timeout)
222
+ JSON.parse(res[:analysis])
223
+ end
224
+
225
+ class GetIndexOptions
226
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
227
+ attr_accessor :timeout
228
+
229
+ # @yieldparam [GetIndexOptions] self
230
+ def initialize
231
+ yield self if block_given?
232
+ end
233
+ end
234
+
235
+ class GetAllIndexesOptions
236
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
237
+ attr_accessor :timeout
238
+
239
+ # @yieldparam [GetAllIndexesOptions] self
240
+ def initialize
241
+ yield self if block_given?
242
+ end
243
+ end
244
+
245
+ class UpsertIndexOptions
246
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
247
+ attr_accessor :timeout
248
+
249
+ # @yieldparam [UpsertIndexOptions] self
250
+ def initialize
251
+ yield self if block_given?
252
+ end
253
+ end
254
+
255
+ class DropIndexOptions
256
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
257
+ attr_accessor :timeout
258
+
259
+ # @yieldparam [DropIndexOptions] self
260
+ def initialize
261
+ yield self if block_given?
262
+ end
263
+ end
264
+
265
+ class GetIndexedDocumentsCountOptions
266
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
267
+ attr_accessor :timeout
268
+
269
+ # @yieldparam [GetIndexedDocumentCountOptions] self
270
+ def initialize
271
+ yield self if block_given?
272
+ end
273
+ end
274
+
275
+ class GetIndexStatsOptions
276
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
277
+ attr_accessor :timeout
278
+
279
+ # @yieldparam [GetStatsOptions] self
280
+ def initialize
281
+ yield self if block_given?
282
+ end
283
+ end
284
+
285
+ class PauseIngestOptions
286
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
287
+ attr_accessor :timeout
288
+
289
+ # @yieldparam [PauseIngestOptions] self
290
+ def initialize
291
+ yield self if block_given?
292
+ end
293
+ end
294
+
295
+ class ResumeIngestOptions
296
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
297
+ attr_accessor :timeout
298
+
299
+ # @yieldparam [ResumeIngestOptions] self
300
+ def initialize
301
+ yield self if block_given?
302
+ end
303
+ end
304
+
305
+ class AllowQueryingOptions
306
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
307
+ attr_accessor :timeout
308
+
309
+ # @yieldparam [AllowQueryingOptions] self
310
+ def initialize
311
+ yield self if block_given?
312
+ end
313
+ end
314
+
315
+ class DisallowQueryingOptions
316
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
317
+ attr_accessor :timeout
318
+
319
+ # @yieldparam [DisallowQueryingOptions] self
320
+ def initialize
321
+ yield self if block_given?
322
+ end
323
+ end
324
+
325
+ class FreezePlanOptions
326
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
327
+ attr_accessor :timeout
328
+
329
+ # @yieldparam [FreezePlanOptions] self
330
+ def initialize
331
+ yield self if block_given?
332
+ end
333
+ end
334
+
335
+ class UnfreezePlanOptions
336
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
337
+ attr_accessor :timeout
338
+
339
+ # @yieldparam [UnfreezePlanOptions] self
340
+ def initialize
341
+ yield self if block_given?
342
+ end
343
+ end
344
+
345
+ class AnalyzeDocumentOptions
346
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
347
+ attr_accessor :timeout
348
+
349
+ # @yieldparam [AnalyzeDocumentOptions] self
350
+ def initialize
351
+ yield self if block_given?
352
+ end
353
+ end
354
+
355
+ private
356
+
357
+ def extract_search_index(resp)
358
+ SearchIndex.new do |index|
359
+ index.name = resp[:name]
360
+ index.type = resp[:type]
361
+ index.uuid = resp[:uuid]
362
+ index.params = resp[:params] ? JSON.parse(resp[:params]) : {}
363
+ index.source_name = resp[:source_name]
364
+ index.source_type = resp[:source_type]
365
+ index.source_uuid = resp[:source_uuid]
366
+ index.source_params = resp[:source_params] ? JSON.parse(resp[:source_params]) : {}
367
+ index.plan_params = resp[:plan_params] ? JSON.parse(resp[:plan_params]) : {}
368
+ end
369
+ end
370
+ end
371
+
372
+ class SearchIndex
373
+ # @return [String] name of the index
374
+ attr_accessor :name
375
+
376
+ # @return [String] type of the index
377
+ attr_accessor :type
378
+
379
+ # @return [String] UUID is required for update. It provides means of ensuring consistency.
380
+ attr_accessor :uuid
381
+
382
+ # @return [Hash] index properties such as store type and mappings
383
+ attr_accessor :params
384
+
385
+ # @return [String] name of the source of the data for the index (e.g. bucket name)
386
+ attr_accessor :source_name
387
+
388
+ # @return [String] type of the data source
389
+ attr_accessor :source_type
390
+
391
+ # @return [String] the UUID of the ata source, this can be used to more tightly tie the index to a source
392
+ attr_accessor :source_uuid
393
+
394
+ # @return [Hash] extra parameters for the source. These are usually things like advanced connection and tuning.
395
+ attr_accessor :source_params
396
+
397
+ # @return [Hash] plan properties such a number of replicas and number of partitions
398
+ attr_accessor :plan_params
399
+
400
+ # @yieldparam [SearchIndex] self
401
+ def initialize
402
+ @type = "fulltext-index"
403
+ @source_type = "couchbase"
404
+ yield self if block_given?
405
+ end
406
+ end
407
+ end
408
+ end