couchbase 3.5.0-x86_64-darwin-20

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