couchbase 3.5.2-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) 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 +342 -0
  6. data/lib/couchbase/3.1/libcouchbase.bundle +0 -0
  7. data/lib/couchbase/3.2/libcouchbase.bundle +0 -0
  8. data/lib/couchbase/3.3/libcouchbase.bundle +0 -0
  9. data/lib/couchbase/analytics_options.rb +109 -0
  10. data/lib/couchbase/authenticator.rb +66 -0
  11. data/lib/couchbase/binary_collection.rb +130 -0
  12. data/lib/couchbase/binary_collection_options.rb +26 -0
  13. data/lib/couchbase/bucket.rb +146 -0
  14. data/lib/couchbase/cluster.rb +462 -0
  15. data/lib/couchbase/cluster_registry.rb +49 -0
  16. data/lib/couchbase/collection.rb +707 -0
  17. data/lib/couchbase/collection_options.rb +401 -0
  18. data/lib/couchbase/config_profiles.rb +57 -0
  19. data/lib/couchbase/configuration.rb +58 -0
  20. data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
  21. data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
  22. data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
  23. data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
  24. data/lib/couchbase/datastructures.rb +26 -0
  25. data/lib/couchbase/diagnostics.rb +183 -0
  26. data/lib/couchbase/errors.rb +414 -0
  27. data/lib/couchbase/json_transcoder.rb +41 -0
  28. data/lib/couchbase/key_value_scan.rb +119 -0
  29. data/lib/couchbase/libcouchbase.rb +6 -0
  30. data/lib/couchbase/logger.rb +87 -0
  31. data/lib/couchbase/management/analytics_index_manager.rb +1129 -0
  32. data/lib/couchbase/management/bucket_manager.rb +445 -0
  33. data/lib/couchbase/management/collection_manager.rb +472 -0
  34. data/lib/couchbase/management/collection_query_index_manager.rb +224 -0
  35. data/lib/couchbase/management/query_index_manager.rb +619 -0
  36. data/lib/couchbase/management/scope_search_index_manager.rb +200 -0
  37. data/lib/couchbase/management/search_index_manager.rb +426 -0
  38. data/lib/couchbase/management/user_manager.rb +470 -0
  39. data/lib/couchbase/management/view_index_manager.rb +239 -0
  40. data/lib/couchbase/management.rb +31 -0
  41. data/lib/couchbase/mutation_state.rb +65 -0
  42. data/lib/couchbase/options.rb +2846 -0
  43. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  44. data/lib/couchbase/protostellar/bucket.rb +55 -0
  45. data/lib/couchbase/protostellar/client.rb +99 -0
  46. data/lib/couchbase/protostellar/cluster.rb +171 -0
  47. data/lib/couchbase/protostellar/collection.rb +152 -0
  48. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  49. data/lib/couchbase/protostellar/error_handling.rb +203 -0
  50. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +61 -0
  51. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +35 -0
  52. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +57 -0
  53. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +36 -0
  54. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +61 -0
  55. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +37 -0
  56. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +72 -0
  57. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +44 -0
  58. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +52 -0
  59. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +30 -0
  60. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +70 -0
  61. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +36 -0
  62. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +97 -0
  63. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +46 -0
  64. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +57 -0
  65. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +30 -0
  66. data/lib/couchbase/protostellar/generated/routing/v1/routing_pb.rb +52 -0
  67. data/lib/couchbase/protostellar/generated/routing/v1/routing_services_pb.rb +30 -0
  68. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +99 -0
  69. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +30 -0
  70. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +57 -0
  71. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +36 -0
  72. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +51 -0
  73. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +30 -0
  74. data/lib/couchbase/protostellar/generated.rb +9 -0
  75. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  76. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  77. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  78. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  79. data/lib/couchbase/protostellar/management.rb +24 -0
  80. data/lib/couchbase/protostellar/request.rb +78 -0
  81. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  82. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  83. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +94 -0
  84. data/lib/couchbase/protostellar/request_generator/admin/query.rb +130 -0
  85. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  86. data/lib/couchbase/protostellar/request_generator/kv.rb +474 -0
  87. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  88. data/lib/couchbase/protostellar/request_generator/search.rb +387 -0
  89. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  90. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  91. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  92. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  93. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  94. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  95. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  96. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  97. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  98. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  99. data/lib/couchbase/protostellar/retry/orchestrator.rb +60 -0
  100. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  101. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  102. data/lib/couchbase/protostellar/retry/strategies.rb +26 -0
  103. data/lib/couchbase/protostellar/retry.rb +28 -0
  104. data/lib/couchbase/protostellar/scope.rb +57 -0
  105. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  106. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  107. data/lib/couchbase/protostellar.rb +29 -0
  108. data/lib/couchbase/query_options.rb +122 -0
  109. data/lib/couchbase/railtie.rb +47 -0
  110. data/lib/couchbase/raw_binary_transcoder.rb +39 -0
  111. data/lib/couchbase/raw_json_transcoder.rb +40 -0
  112. data/lib/couchbase/raw_string_transcoder.rb +42 -0
  113. data/lib/couchbase/scope.rb +258 -0
  114. data/lib/couchbase/search_options.rb +1650 -0
  115. data/lib/couchbase/subdoc.rb +293 -0
  116. data/lib/couchbase/transcoder_flags.rb +64 -0
  117. data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
  118. data/lib/couchbase/utils/stdlib_logger_adapter.rb +67 -0
  119. data/lib/couchbase/utils/time.rb +71 -0
  120. data/lib/couchbase/utils.rb +23 -0
  121. data/lib/couchbase/version.rb +25 -0
  122. data/lib/couchbase/view_options.rb +67 -0
  123. data/lib/couchbase.rb +30 -0
  124. data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
  125. metadata +190 -0
@@ -0,0 +1,619 @@
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/errors"
18
+ require "couchbase/options"
19
+ require "couchbase/utils/time"
20
+
21
+ module Couchbase
22
+ module Management
23
+ module Options
24
+ module Query
25
+ # Options for {QueryIndexManager#get_all_indexes}
26
+ class GetAllIndexes < ::Couchbase::Options::Base
27
+ attr_accessor :scope_name # @return [String, nil]
28
+ attr_accessor :collection_name # @return [String, nil]
29
+
30
+ # Creates an instance of options for {QueryIndexManager#get_all_indexes}
31
+ #
32
+ # @param [String, nil] scope_name the name of the scope
33
+ # @param [String, nil] collection_name the name of the collection
34
+ #
35
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
36
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
37
+ # @param [Hash, nil] client_context the client context data, if set
38
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
39
+ #
40
+ # @yieldparam [GetAllScopes] self
41
+ def initialize(scope_name: nil,
42
+ collection_name: nil,
43
+ timeout: nil,
44
+ retry_strategy: nil,
45
+ client_context: nil,
46
+ parent_span: nil)
47
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
48
+ @scope_name = scope_name
49
+ @collection_name = collection_name
50
+ yield self if block_given?
51
+ end
52
+
53
+ # @api private
54
+ def to_backend
55
+ {
56
+ timeout: Utils::Time.extract_duration(@timeout),
57
+ scope_name: @scope_name,
58
+ collection_name: @collection_name,
59
+ }
60
+ end
61
+ end
62
+
63
+ # Options for {QueryIndexManager#create_index}
64
+ class CreateIndex < ::Couchbase::Options::Base
65
+ attr_accessor :ignore_if_exists # @return [Boolean]
66
+ attr_accessor :num_replicas # @return [Integer, nil]
67
+ attr_accessor :deferred # @return [Boolean]
68
+ attr_accessor :condition # @return [String, nil]
69
+ attr_accessor :scope_name # @return [String, nil]
70
+ attr_accessor :collection_name # @return [String, nil]
71
+
72
+ # Creates an instance of options for {QueryIndexManager#create_index}
73
+ #
74
+ # @param [Boolean] ignore_if_exists do not raise error if the index already exist
75
+ # @param [Integer] num_replicas the number of replicas that this index should have
76
+ # @param [Boolean] deferred whether the index should be created as a deferred index.
77
+ # @param [String, nil] condition to apply to the index
78
+ # @param [String, nil] scope_name the name of the scope
79
+ # @param [String, nil] collection_name the name of the collection
80
+ #
81
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
82
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
83
+ # @param [Hash, nil] client_context the client context data, if set
84
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
85
+ #
86
+ # @yieldparam [CreateIndex] self
87
+ def initialize(ignore_if_exists: false,
88
+ num_replicas: nil,
89
+ deferred: false,
90
+ condition: nil,
91
+ scope_name: nil,
92
+ collection_name: nil,
93
+ timeout: nil,
94
+ retry_strategy: nil,
95
+ client_context: nil,
96
+ parent_span: nil)
97
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
98
+ @ignore_if_exists = ignore_if_exists
99
+ @num_replicas = num_replicas
100
+ @deferred = deferred
101
+ @condition = condition
102
+ @scope_name = scope_name
103
+ @collection_name = collection_name
104
+ yield self if block_given?
105
+ end
106
+
107
+ # @api private
108
+ def to_backend
109
+ {
110
+ timeout: Utils::Time.extract_duration(@timeout),
111
+ ignore_if_exists: @ignore_if_exists,
112
+ condition: @condition,
113
+ deferred: @deferred,
114
+ num_replicas: @num_replicas,
115
+ scope_name: @scope_name,
116
+ collection_name: @collection_name,
117
+ }
118
+ end
119
+ end
120
+
121
+ # Options for {QueryIndexManager#create_primary_index}
122
+ class CreatePrimaryIndex < ::Couchbase::Options::Base
123
+ attr_accessor :ignore_if_exists # @return [Boolean]
124
+ attr_accessor :num_replicas # @return [Integer, nil]
125
+ attr_accessor :deferred # @return [Boolean]
126
+ attr_accessor :index_name # @return [String. nil]
127
+ attr_accessor :scope_name # @return [String, nil]
128
+ attr_accessor :collection_name # @return [String, nil]
129
+
130
+ # Creates an instance of options for {QueryIndexManager#create_primary_index}
131
+ #
132
+ # @param [Boolean] ignore_if_exists do not raise error if the index already exist
133
+ # @param [Integer] num_replicas the number of replicas that this index should have
134
+ # @param [Boolean] deferred whether the index should be created as a deferred index.
135
+ # @param [String, nil] index_name the custom name of the primary index.
136
+ # @param [String, nil] scope_name the name of the scope
137
+ # @param [String, nil] collection_name the name of the collection
138
+ #
139
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
140
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
141
+ # @param [Hash, nil] client_context the client context data, if set
142
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
143
+ #
144
+ # @yieldparam [CreatePrimaryIndex] self
145
+ def initialize(ignore_if_exists: false,
146
+ num_replicas: nil,
147
+ deferred: false,
148
+ index_name: nil,
149
+ scope_name: nil,
150
+ collection_name: nil,
151
+ timeout: nil,
152
+ retry_strategy: nil,
153
+ client_context: nil,
154
+ parent_span: nil)
155
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
156
+ @ignore_if_exists = ignore_if_exists
157
+ @num_replicas = num_replicas
158
+ @deferred = deferred
159
+ @index_name = index_name
160
+ @scope_name = scope_name
161
+ @collection_name = collection_name
162
+ yield self if block_given?
163
+ end
164
+
165
+ # @api private
166
+ def to_backend
167
+ {
168
+ timeout: Utils::Time.extract_duration(@timeout),
169
+ ignore_if_exists: @ignore_if_exists,
170
+ deferred: @deferred,
171
+ num_replicas: @num_replicas,
172
+ index_name: @index_name,
173
+ scope_name: @scope_name,
174
+ collection_name: @collection_name,
175
+ }
176
+ end
177
+ end
178
+
179
+ # Options for {QueryIndexManager#drop_index}
180
+ class DropIndex < ::Couchbase::Options::Base
181
+ attr_accessor :ignore_if_does_not_exist # @return [Boolean]
182
+ attr_accessor :scope_name # @return [String, nil]
183
+ attr_accessor :collection_name # @return [String, nil]
184
+
185
+ # Creates an instance of options for {QueryIndexManager#drop_index}
186
+ #
187
+ # @param [Boolean] ignore_if_does_not_exist do not raise error if the index does not exist
188
+ # @param [String, nil] scope_name the name of the scope
189
+ # @param [String, nil] collection_name the name of the collection
190
+ #
191
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
192
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
193
+ # @param [Hash, nil] client_context the client context data, if set
194
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
195
+ #
196
+ # @yieldparam [DropIndex] self
197
+ def initialize(ignore_if_does_not_exist: false,
198
+ scope_name: nil,
199
+ collection_name: nil,
200
+ timeout: nil,
201
+ retry_strategy: nil,
202
+ client_context: nil,
203
+ parent_span: nil)
204
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
205
+ @ignore_if_does_not_exist = ignore_if_does_not_exist
206
+ @scope_name = scope_name
207
+ @collection_name = collection_name
208
+ yield self if block_given?
209
+ end
210
+
211
+ # @api private
212
+ def to_backend
213
+ {
214
+ timeout: Utils::Time.extract_duration(@timeout),
215
+ ignore_if_does_not_exist: @ignore_if_does_not_exist,
216
+ scope_name: @scope_name,
217
+ collection_name: @collection_name,
218
+ }
219
+ end
220
+ end
221
+
222
+ # Options for {QueryIndexManager#drop_primary_index}
223
+ class DropPrimaryIndex < ::Couchbase::Options::Base
224
+ attr_accessor :ignore_if_does_not_exist # @return [Boolean]
225
+ attr_accessor :scope_name # @return [String, nil]
226
+ attr_accessor :collection_name # @return [String, nil]
227
+
228
+ # Creates an instance of options for {QueryIndexManager#drop_primary_index}
229
+ #
230
+ # @param [Boolean] ignore_if_does_not_exist do not raise error if the index does not exist
231
+ # @param [String, nil] scope_name the name of the scope
232
+ # @param [String, nil] collection_name the name of the collection
233
+ #
234
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
235
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
236
+ # @param [Hash, nil] client_context the client context data, if set
237
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
238
+ #
239
+ # @yieldparam [DropPrimaryIndex] self
240
+ def initialize(ignore_if_does_not_exist: false,
241
+ scope_name: nil,
242
+ collection_name: nil,
243
+ timeout: nil,
244
+ retry_strategy: nil,
245
+ client_context: nil,
246
+ parent_span: nil)
247
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
248
+ @ignore_if_does_not_exist = ignore_if_does_not_exist
249
+ @scope_name = scope_name
250
+ @collection_name = collection_name
251
+ yield self if block_given?
252
+ end
253
+
254
+ # @api private
255
+ def to_backend
256
+ {
257
+ timeout: Utils::Time.extract_duration(@timeout),
258
+ ignore_if_does_not_exist: @ignore_if_does_not_exist,
259
+ scope_name: @scope_name,
260
+ collection_name: @collection_name,
261
+ }
262
+ end
263
+ end
264
+
265
+ # Options for {QueryIndexManager#build_deferred_indexes}
266
+ class BuildDeferredIndexes < ::Couchbase::Options::Base
267
+ attr_accessor :scope_name # @return [String, nil]
268
+ attr_accessor :collection_name # @return [String, nil]
269
+
270
+ # Creates an instance of options for {QueryIndexManager#build_deferred_indexes}
271
+ # @param [String, nil] scope_name the name of the scope
272
+ # @param [String, nil] collection_name the name of the collection
273
+ #
274
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
275
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
276
+ # @param [Hash, nil] client_context the client context data, if set
277
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
278
+ #
279
+ # @yieldparam [GetAllScopes] self
280
+ def initialize(scope_name: nil,
281
+ collection_name: nil,
282
+ timeout: nil,
283
+ retry_strategy: nil,
284
+ client_context: nil,
285
+ parent_span: nil)
286
+ super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
287
+ @scope_name = scope_name
288
+ @collection_name = collection_name
289
+ yield self if block_given?
290
+ end
291
+
292
+ # @api private
293
+ def to_backend
294
+ {
295
+ timeout: Utils::Time.extract_duration(@timeout),
296
+ scope_name: @scope_name,
297
+ collection_name: @collection_name,
298
+ }
299
+ end
300
+ end
301
+
302
+ # Options for {QueryIndexManager#watch_indexes}
303
+ class WatchIndexes < ::Couchbase::Options::Base
304
+ attr_accessor :watch_primary # @return [Boolean]
305
+ attr_accessor :scope_name # @return [String, nil]
306
+ attr_accessor :collection_name # @return [String, nil]
307
+
308
+ # Creates an instance of options for {QueryIndexManager#watch_indexes}
309
+ #
310
+ # @param [Boolean] watch_primary whether or not to watch the primary index
311
+ # @param [String, nil] scope_name the name of the scope
312
+ # @param [String, nil] collection_name the name of the collection
313
+ #
314
+ # @param [Proc, nil] retry_strategy the custom retry strategy, if set
315
+ # @param [Hash, nil] client_context the client context data, if set
316
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
317
+ #
318
+ # @yieldparam [GetAllScopes] self
319
+ def initialize(watch_primary: false,
320
+ scope_name: nil,
321
+ collection_name: nil,
322
+ retry_strategy: nil,
323
+ client_context: nil,
324
+ parent_span: nil)
325
+ super(timeout: nil, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
326
+ @watch_primary = watch_primary
327
+ @scope_name = scope_name
328
+ @collection_name = collection_name
329
+ yield self if block_given?
330
+ end
331
+
332
+ # @api private
333
+ def to_backend
334
+ {
335
+ watch_primary: @watch_primary,
336
+ scope_name: @scope_name,
337
+ collection_name: @collection_name,
338
+ }
339
+ end
340
+ end
341
+
342
+ # rubocop:disable Naming/MethodName constructor shortcuts
343
+ module_function
344
+
345
+ # Construct {GetAllIndexes} options for {QueryIndexManager#get_all_indexes}
346
+ #
347
+ # @return [GetAllIndexes]
348
+ def GetAllIndexes(**args)
349
+ GetAllIndexes.new(**args)
350
+ end
351
+
352
+ # Construct {CreateIndex} options for {QueryIndexManager#create_index}
353
+ #
354
+ # @return [CreateIndex]
355
+ def CreateIndex(**args)
356
+ CreateIndex.new(**args)
357
+ end
358
+
359
+ # Construct {CreatePrimaryIndex} options for {QueryIndexManager#create_index}
360
+ #
361
+ # @return [CreatePrimaryIndex]
362
+ def CreatePrimaryIndex(**args)
363
+ CreatePrimaryIndex.new(**args)
364
+ end
365
+
366
+ # Construct {DropIndex} options for {QueryIndexManager#drop_index}
367
+ #
368
+ # @return [DropIndex]
369
+ def DropIndex(**args)
370
+ DropIndex.new(**args)
371
+ end
372
+
373
+ # Construct {DropPrimaryIndex} options for {QueryIndexManager#drop_primary_index}
374
+ #
375
+ # @return [DropPrimaryIndex]
376
+ def DropPrimaryIndex(**args)
377
+ DropPrimaryIndex.new(**args)
378
+ end
379
+
380
+ # rubocop:enable Naming/MethodName
381
+ end
382
+ end
383
+
384
+ class QueryIndexManager
385
+ alias inspect to_s
386
+
387
+ # @param [Couchbase::Backend] backend
388
+ def initialize(backend)
389
+ @backend = backend
390
+ end
391
+
392
+ # Fetches all indexes from the server
393
+ #
394
+ # @param [String] bucket_name name of the bucket
395
+ # @param [Options::Query::GetAllIndexes] options
396
+ #
397
+ # @return [Array<QueryIndex>]
398
+ #
399
+ # @raise [ArgumentError]
400
+ def get_all_indexes(bucket_name, options = GetAllIndexOptions.new)
401
+ unless options.scope_name.nil? && options.collection_name.nil?
402
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
403
+ end
404
+
405
+ res = @backend.query_index_get_all(bucket_name, options.to_backend)
406
+ res[:indexes].map do |idx|
407
+ QueryIndex.new do |index|
408
+ index.name = idx[:name]
409
+ index.is_primary = idx[:is_primary]
410
+ index.type = idx[:type]
411
+ index.state = idx[:state]
412
+ index.bucket = idx[:bucket_name]
413
+ index.scope = idx[:scope_name]
414
+ index.collection = idx[:collection_name]
415
+ index.index_key = idx[:index_key]
416
+ index.condition = idx[:condition]
417
+ index.partition = idx[:partition]
418
+ end
419
+ end
420
+ end
421
+
422
+ # Creates a new index
423
+ #
424
+ # @param [String] bucket_name name of the bucket
425
+ # @param [String] index_name name of the index
426
+ # @param [Array<String>] fields the lists of fields to create th index over
427
+ # @param [Options::Query::CreateIndex] options
428
+ #
429
+ # @return void
430
+ #
431
+ # @raise [ArgumentError]
432
+ # @raise [Error::IndexExists]
433
+ def create_index(bucket_name, index_name, fields, options = Options::Query::CreateIndex.new)
434
+ unless options.scope_name.nil? && options.collection_name.nil?
435
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
436
+ end
437
+
438
+ @backend.query_index_create(bucket_name, index_name, fields, options.to_backend)
439
+ end
440
+
441
+ # Creates new primary index
442
+ #
443
+ # @param [String] bucket_name name of the bucket
444
+ # @param [Options::Query::CreatePrimaryIndex] options
445
+ #
446
+ # @return void
447
+ #
448
+ # @raise [ArgumentError]
449
+ # @raise [Error::IndexExists]
450
+ def create_primary_index(bucket_name, options = Options::Query::CreatePrimaryIndex.new)
451
+ unless options.scope_name.nil? && options.collection_name.nil?
452
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
453
+ end
454
+
455
+ @backend.query_index_create_primary(bucket_name, options.to_backend)
456
+ end
457
+
458
+ # Drops the index
459
+ #
460
+ # @param [String] bucket_name name of the bucket
461
+ # @param [String] index_name name of the index
462
+ # @param [Options::Query::DropIndex] options
463
+ #
464
+ # @return void
465
+ #
466
+ # @raise [ArgumentError]
467
+ # @raise [Error::IndexNotFound]
468
+ def drop_index(bucket_name, index_name, options = Options::Query::DropIndex.new)
469
+ unless options.scope_name.nil? && options.collection_name.nil?
470
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
471
+ end
472
+
473
+ @backend.query_index_drop(bucket_name, index_name, options.to_backend)
474
+ end
475
+
476
+ # Drops the primary index
477
+ #
478
+ # @param [String] bucket_name name of the bucket
479
+ # @param [Options::Query::DropPrimaryIndex] options
480
+ #
481
+ # @return void
482
+ #
483
+ # @raise [ArgumentError]
484
+ # @raise [Error::IndexNotFound]
485
+ def drop_primary_index(bucket_name, options = Options::Query::DropPrimaryIndex.new)
486
+ unless options.scope_name.nil? && options.collection_name.nil?
487
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
488
+ end
489
+
490
+ @backend.query_index_drop_primary(bucket_name, options.to_backend)
491
+ end
492
+
493
+ # Build all indexes which are currently in deferred state
494
+ #
495
+ # @param [String] bucket_name name of the bucket
496
+ # @param [Options::Query::BuildDeferredIndexes] options
497
+ #
498
+ # @return
499
+ #
500
+ # @raise [ArgumentError]
501
+ def build_deferred_indexes(bucket_name, options = Options::Query::BuildDeferredIndexes.new)
502
+ unless options.scope_name.nil? && options.collection_name.nil?
503
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
504
+ end
505
+
506
+ @backend.query_index_build_deferred(bucket_name, options.to_backend)
507
+ end
508
+
509
+ # Polls indexes until they are online
510
+ #
511
+ # @param [String] bucket_name name of the bucket
512
+ # @param [Array<String>] index_names names of the indexes to watch
513
+ # @param [Integer, #in_milliseconds] timeout the time in milliseconds allowed for the operation to complete
514
+ # @param [Options::Query::WatchIndexes] options
515
+ #
516
+ # @raise [ArgumentError]
517
+ # @raise [Error::IndexNotFound]
518
+ def watch_indexes(bucket_name, index_names, timeout, options = Options::Query::WatchIndexes.new)
519
+ unless options.scope_name.nil? && options.collection_name.nil?
520
+ warn "The attributes 'scope_name' and 'collection_name' have been deprecated. Use 'collection.query_indexes' instead"
521
+ end
522
+
523
+ index_names.append("#primary") if options.watch_primary
524
+
525
+ interval_millis = 50
526
+ deadline = Time.now + (Utils::Time.extract_duration(timeout) * 0.001)
527
+ while Time.now <= deadline
528
+ get_all_opts = Options::Query::GetAllIndexes.new(timeout: ((deadline - Time.now) * 1000).round)
529
+ indexes = get_all_indexes(bucket_name, get_all_opts).select { |idx| index_names.include? idx.name }
530
+ indexes_not_found = index_names - indexes.map(&:name)
531
+ raise Error::IndexNotFound, "Failed to find the indexes: #{indexes_not_found.join(', ')}" unless indexes_not_found.empty?
532
+
533
+ all_online = indexes.all? { |idx| idx.state == :online }
534
+ return if all_online
535
+
536
+ sleep(interval_millis / 1000)
537
+ interval_millis += 500
538
+ interval_millis = 1000 if interval_millis > 1000
539
+ end
540
+ raise Error::UnambiguousTimeout, "Failed to find all indexes online within the allotted time"
541
+ end
542
+
543
+ # @api private
544
+ # TODO: deprecate after 3.2
545
+ GetAllIndexOptions = ::Couchbase::Management::Options::Query::GetAllIndexes
546
+
547
+ # @api private
548
+ # TODO: deprecate after 3.2
549
+ CreateIndexOptions = ::Couchbase::Management::Options::Query::CreateIndex
550
+
551
+ # @api private
552
+ # TODO: deprecate after 3.2
553
+ CreatePrimaryIndexOptions = ::Couchbase::Management::Options::Query::CreatePrimaryIndex
554
+
555
+ # @api private
556
+ # TODO: deprecate after 3.2
557
+ DropIndexOptions = ::Couchbase::Management::Options::Query::DropIndex
558
+
559
+ # @api private
560
+ # TODO: deprecate after 3.2
561
+ DropPrimaryIndexOptions = ::Couchbase::Management::Options::Query::DropPrimaryIndex
562
+
563
+ # @api private
564
+ # TODO: deprecate after 3.2
565
+ BuildDeferredIndexOptions = ::Couchbase::Management::Options::Query::BuildDeferredIndexes
566
+
567
+ # @api private
568
+ # TODO: deprecate after 3.2
569
+ WatchIndexesOptions = ::Couchbase::Management::Options::Query::WatchIndexes
570
+ end
571
+
572
+ class QueryIndex
573
+ # @return [String] name of the index
574
+ attr_accessor :name
575
+
576
+ # @return [Boolean] true if this is a primary index
577
+ attr_accessor :is_primary
578
+ alias primary? is_primary
579
+
580
+ # @return [:gsi, :view] type of the index
581
+ attr_accessor :type
582
+
583
+ # @return [Symbol] state
584
+ attr_accessor :state
585
+
586
+ # @return [String, nil] the name of the bucket
587
+ attr_accessor :bucket
588
+
589
+ # @return [String, nil] the name of the scope
590
+ attr_accessor :scope
591
+
592
+ # @return [String, nil] the name of the collection
593
+ attr_accessor :collection
594
+
595
+ # @return [Array<String>] an array of Strings that represent the index key(s). The array is empty in the case of a
596
+ # PRIMARY INDEX.
597
+ #
598
+ # @note the query service can present the key in a slightly different manner from when you declared the index: for
599
+ # instance, it will show the indexed fields in an escaped format (surrounded by backticks).
600
+ attr_accessor :index_key
601
+
602
+ # @return [String] the string representation of the index's condition (the WHERE clause of the index),
603
+ # or an empty Optional if no condition was set.
604
+ #
605
+ # @note that the query service can present the condition in a slightly different manner from when you declared the
606
+ # index. For instance it will wrap expressions with parentheses and show the fields in an escaped format
607
+ # (surrounded by backticks).
608
+ attr_accessor :condition
609
+
610
+ # @return [String] the string representation of the index's partition
611
+ attr_accessor :partition
612
+
613
+ # @yieldparam [QueryIndex] self
614
+ def initialize
615
+ yield self if block_given?
616
+ end
617
+ end
618
+ end
619
+ end