couchbase 3.9.0-aarch64-mingw-ucrt

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) 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 +407 -0
  6. data/lib/couchbase/3.4/libcouchbase.so +0 -0
  7. data/lib/couchbase/4.0/libcouchbase.so +0 -0
  8. data/lib/couchbase/analytics_options.rb +109 -0
  9. data/lib/couchbase/authenticator.rb +80 -0
  10. data/lib/couchbase/binary_collection.rb +145 -0
  11. data/lib/couchbase/binary_collection_options.rb +26 -0
  12. data/lib/couchbase/bucket.rb +173 -0
  13. data/lib/couchbase/cluster.rb +555 -0
  14. data/lib/couchbase/cluster_registry.rb +49 -0
  15. data/lib/couchbase/collection.rb +770 -0
  16. data/lib/couchbase/collection_options.rb +401 -0
  17. data/lib/couchbase/config_profiles.rb +57 -0
  18. data/lib/couchbase/configuration.rb +58 -0
  19. data/lib/couchbase/datastructures/couchbase_list.rb +192 -0
  20. data/lib/couchbase/datastructures/couchbase_map.rb +231 -0
  21. data/lib/couchbase/datastructures/couchbase_queue.rb +161 -0
  22. data/lib/couchbase/datastructures/couchbase_set.rb +145 -0
  23. data/lib/couchbase/datastructures.rb +26 -0
  24. data/lib/couchbase/deprecations.rb +61 -0
  25. data/lib/couchbase/diagnostics.rb +183 -0
  26. data/lib/couchbase/errors.rb +438 -0
  27. data/lib/couchbase/fork_hooks.rb +41 -0
  28. data/lib/couchbase/get_replica_strategy.rb +89 -0
  29. data/lib/couchbase/json_transcoder.rb +41 -0
  30. data/lib/couchbase/key_value_scan.rb +119 -0
  31. data/lib/couchbase/libcouchbase.rb +6 -0
  32. data/lib/couchbase/logger.rb +87 -0
  33. data/lib/couchbase/management/analytics_index_manager.rb +1160 -0
  34. data/lib/couchbase/management/bucket_manager.rb +479 -0
  35. data/lib/couchbase/management/collection_manager.rb +515 -0
  36. data/lib/couchbase/management/collection_query_index_manager.rb +247 -0
  37. data/lib/couchbase/management/query_index_manager.rb +671 -0
  38. data/lib/couchbase/management/scope_search_index_manager.rb +267 -0
  39. data/lib/couchbase/management/search_index_manager.rb +649 -0
  40. data/lib/couchbase/management/user_manager.rb +639 -0
  41. data/lib/couchbase/management/view_index_manager.rb +332 -0
  42. data/lib/couchbase/management.rb +31 -0
  43. data/lib/couchbase/metrics/logging_meter.rb +108 -0
  44. data/lib/couchbase/metrics/logging_value_recorder.rb +50 -0
  45. data/lib/couchbase/metrics/meter.rb +27 -0
  46. data/lib/couchbase/metrics/noop_meter.rb +30 -0
  47. data/lib/couchbase/metrics/noop_value_recorder.rb +27 -0
  48. data/lib/couchbase/metrics/value_recorder.rb +25 -0
  49. data/lib/couchbase/mutation_state.rb +65 -0
  50. data/lib/couchbase/options.rb +3097 -0
  51. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  52. data/lib/couchbase/protostellar/bucket.rb +59 -0
  53. data/lib/couchbase/protostellar/client.rb +97 -0
  54. data/lib/couchbase/protostellar/cluster.rb +182 -0
  55. data/lib/couchbase/protostellar/collection.rb +156 -0
  56. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  57. data/lib/couchbase/protostellar/error_handling.rb +204 -0
  58. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_pb.rb +54 -0
  59. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_services_pb.rb +51 -0
  60. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +42 -0
  61. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +51 -0
  62. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +38 -0
  63. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +52 -0
  64. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +42 -0
  65. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +55 -0
  66. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +51 -0
  67. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +67 -0
  68. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +31 -0
  69. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +40 -0
  70. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +51 -0
  71. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +54 -0
  72. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_pb.rb +46 -0
  73. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_services_pb.rb +56 -0
  74. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +74 -0
  75. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +93 -0
  76. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +35 -0
  77. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +40 -0
  78. data/lib/couchbase/protostellar/generated/routing/v2/routing_pb.rb +26 -0
  79. data/lib/couchbase/protostellar/generated/routing/v2/routing_services_pb.rb +43 -0
  80. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +78 -0
  81. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +41 -0
  82. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +36 -0
  83. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +66 -0
  84. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +30 -0
  85. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +39 -0
  86. data/lib/couchbase/protostellar/generated.rb +9 -0
  87. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  88. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  89. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  90. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  91. data/lib/couchbase/protostellar/management.rb +24 -0
  92. data/lib/couchbase/protostellar/request.rb +79 -0
  93. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  94. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  95. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +96 -0
  96. data/lib/couchbase/protostellar/request_generator/admin/query.rb +132 -0
  97. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  98. data/lib/couchbase/protostellar/request_generator/kv.rb +488 -0
  99. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  100. data/lib/couchbase/protostellar/request_generator/search.rb +403 -0
  101. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  102. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  103. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  104. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  105. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  106. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  107. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  108. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  109. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  110. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  111. data/lib/couchbase/protostellar/retry/orchestrator.rb +61 -0
  112. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  113. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  114. data/lib/couchbase/protostellar/retry/strategies/fail_fast.rb +33 -0
  115. data/lib/couchbase/protostellar/retry/strategies.rb +27 -0
  116. data/lib/couchbase/protostellar/retry.rb +28 -0
  117. data/lib/couchbase/protostellar/scope.rb +61 -0
  118. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  119. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  120. data/lib/couchbase/protostellar.rb +29 -0
  121. data/lib/couchbase/query_options.rb +122 -0
  122. data/lib/couchbase/railtie.rb +47 -0
  123. data/lib/couchbase/raw_binary_transcoder.rb +39 -0
  124. data/lib/couchbase/raw_json_transcoder.rb +40 -0
  125. data/lib/couchbase/raw_string_transcoder.rb +42 -0
  126. data/lib/couchbase/scope.rb +272 -0
  127. data/lib/couchbase/search_options.rb +1744 -0
  128. data/lib/couchbase/subdoc.rb +293 -0
  129. data/lib/couchbase/tracing/noop_span.rb +29 -0
  130. data/lib/couchbase/tracing/noop_tracer.rb +29 -0
  131. data/lib/couchbase/tracing/request_span.rb +34 -0
  132. data/lib/couchbase/tracing/request_tracer.rb +28 -0
  133. data/lib/couchbase/tracing/threshold_logging_span.rb +112 -0
  134. data/lib/couchbase/tracing/threshold_logging_tracer.rb +231 -0
  135. data/lib/couchbase/transcoder_flags.rb +64 -0
  136. data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
  137. data/lib/couchbase/utils/hdr_histogram.rb +55 -0
  138. data/lib/couchbase/utils/observability.rb +263 -0
  139. data/lib/couchbase/utils/observability_constants.rb +200 -0
  140. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  141. data/lib/couchbase/utils/time.rb +71 -0
  142. data/lib/couchbase/utils.rb +23 -0
  143. data/lib/couchbase/version.rb +25 -0
  144. data/lib/couchbase/view_options.rb +67 -0
  145. data/lib/couchbase.rb +32 -0
  146. data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
  147. metadata +209 -0
@@ -0,0 +1,272 @@
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/query_options"
19
+ require "couchbase/analytics_options"
20
+
21
+ module Couchbase
22
+ # The scope identifies a group of collections and allows high application density as a result.
23
+ class Scope
24
+ attr_reader :bucket_name
25
+ attr_reader :name
26
+
27
+ alias inspect to_s
28
+
29
+ # @param [Couchbase::Backend] backend
30
+ # @param [String] bucket_name name of the bucket
31
+ # @param [String] scope_name name of the scope
32
+ def initialize(backend, bucket_name, scope_name, observability)
33
+ @backend = backend
34
+ @bucket_name = bucket_name
35
+ @name = scope_name
36
+ @observability = observability
37
+ end
38
+
39
+ # Opens the default collection for this scope
40
+ #
41
+ # @param [String] collection_name name of the collection
42
+ #
43
+ # @return [Collection]
44
+ def collection(collection_name)
45
+ Collection.new(@backend, @bucket_name, @name, collection_name, @observability)
46
+ end
47
+
48
+ # Performs a query against the query (N1QL) services.
49
+ #
50
+ # The query will be implicitly scoped using current bucket and scope names.
51
+ #
52
+ # @see Options::Query#scope_qualifier
53
+ # @see Cluster#query
54
+ #
55
+ # @param [String] statement the N1QL query statement
56
+ # @param [Options::Query] options the custom options for this query
57
+ #
58
+ # @example Select first ten hotels from travel sample dataset
59
+ # scope.query("SELECT * FROM `travel-sample` WHERE type = $type LIMIT 10",
60
+ # Options::Query(named_parameters: {type: "hotel"}, metrics: true))
61
+ #
62
+ # @return [QueryResult]
63
+ def query(statement, options = Options::Query::DEFAULT)
64
+ @observability.record_operation(Observability::OP_QUERY, options.parent_span, self, :query) do |obs_handler|
65
+ obs_handler.add_query_statement(statement, options)
66
+
67
+ resp = @backend.document_query(statement, options.to_backend(scope_name: @name, bucket_name: @bucket_name), obs_handler)
68
+
69
+ Cluster::QueryResult.new do |res|
70
+ res.meta_data = Cluster::QueryMetaData.new do |meta|
71
+ meta.status = resp[:meta][:status]
72
+ meta.request_id = resp[:meta][:request_id]
73
+ meta.client_context_id = resp[:meta][:client_context_id]
74
+ meta.signature = JSON.parse(resp[:meta][:signature]) if resp[:meta][:signature]
75
+ meta.profile = JSON.parse(resp[:meta][:profile]) if resp[:meta][:profile]
76
+ meta.metrics = Cluster::QueryMetrics.new do |metrics|
77
+ if resp[:meta][:metrics]
78
+ metrics.elapsed_time = resp[:meta][:metrics][:elapsed_time]
79
+ metrics.execution_time = resp[:meta][:metrics][:execution_time]
80
+ metrics.sort_count = resp[:meta][:metrics][:sort_count]
81
+ metrics.result_count = resp[:meta][:metrics][:result_count]
82
+ metrics.result_size = resp[:meta][:metrics][:result_size]
83
+ metrics.mutation_count = resp[:meta][:metrics][:mutation_count]
84
+ metrics.error_count = resp[:meta][:metrics][:error_count]
85
+ metrics.warning_count = resp[:meta][:metrics][:warning_count]
86
+ end
87
+ end
88
+ meta.warnings = resp[:warnings].map { |warn| Cluster::QueryWarning.new(warn[:code], warn[:message]) } if resp[:warnings]
89
+ end
90
+ res.instance_variable_set(:@rows, resp[:rows])
91
+ end
92
+ end
93
+ end
94
+
95
+ # Performs an analytics query
96
+ #
97
+ # The query will be implicitly scoped using current bucket and scope names.
98
+ #
99
+ # @param [String] statement the N1QL query statement
100
+ # @param [Options::Analytics] options the custom options for this query
101
+ #
102
+ # @example Select name of the given user
103
+ # scope.analytics_query("SELECT u.name AS uname FROM GleambookUsers u WHERE u.id = $user_id ",
104
+ # Options::Analytics(named_parameters: {user_id: 2}))
105
+ #
106
+ # @return [AnalyticsResult]
107
+ def analytics_query(statement, options = Options::Analytics::DEFAULT)
108
+ @observability.record_operation(Observability::OP_ANALYTICS_QUERY, options.parent_span, self, :analytics) do |obs_handler|
109
+ obs_handler.add_query_statement(statement, options)
110
+
111
+ resp = @backend.document_analytics(statement, options.to_backend(scope_name: @name, bucket_name: @bucket_name))
112
+
113
+ Cluster::AnalyticsResult.new do |res|
114
+ res.transcoder = options.transcoder
115
+ res.meta_data = Cluster::AnalyticsMetaData.new do |meta|
116
+ meta.status = resp[:meta][:status]
117
+ meta.request_id = resp[:meta][:request_id]
118
+ meta.client_context_id = resp[:meta][:client_context_id]
119
+ meta.signature = JSON.parse(resp[:meta][:signature]) if resp[:meta][:signature]
120
+ meta.profile = JSON.parse(resp[:meta][:profile]) if resp[:meta][:profile]
121
+ meta.metrics = Cluster::AnalyticsMetrics.new do |metrics|
122
+ if resp[:meta][:metrics]
123
+ metrics.elapsed_time = resp[:meta][:metrics][:elapsed_time]
124
+ metrics.execution_time = resp[:meta][:metrics][:execution_time]
125
+ metrics.result_count = resp[:meta][:metrics][:result_count]
126
+ metrics.result_size = resp[:meta][:metrics][:result_size]
127
+ metrics.error_count = resp[:meta][:metrics][:error_count]
128
+ metrics.warning_count = resp[:meta][:metrics][:warning_count]
129
+ metrics.processed_objects = resp[:meta][:metrics][:processed_objects]
130
+ end
131
+ end
132
+ res[:warnings] = resp[:warnings].map { |warn| Cluster::AnalyticsWarning.new(warn[:code], warn[:message]) } if resp[:warnings]
133
+ end
134
+ res.instance_variable_set(:@rows, resp[:rows])
135
+ end
136
+ end
137
+ end
138
+
139
+ # Performs a Full Text Search (FTS) query
140
+ #
141
+ # @param [String] index_name the name of the search index
142
+ # @param [SearchQuery] query the query tree
143
+ # @param [Options::Search] options the query tree
144
+ #
145
+ # @example Return first 10 results of "hop beer" query and request highlighting
146
+ # cluster.search_query("travel_index", Cluster::SearchQuery.match_phrase("green"),
147
+ # Options::Search(
148
+ # limit: 10,
149
+ # collections: ["landmark", "hotel"]
150
+ # fields: %w[name],
151
+ # highlight_style: :html,
152
+ # highlight_fields: %w[name description]
153
+ # ))
154
+ #
155
+ # @return [SearchResult]
156
+ def search_query(index_name, query, options = Options::Search::DEFAULT)
157
+ @observability.record_operation(Observability::OP_SEARCH_QUERY, options.parent_span, self, :search) do |obs_handler|
158
+ resp = @backend.document_search(@bucket_name, @name, index_name, JSON.generate(query), {}, options.to_backend, obs_handler)
159
+ convert_search_result(resp, options)
160
+ end
161
+ end
162
+
163
+ # Performs a request against the Full Text Search (FTS) service.
164
+ #
165
+ # @param [String] index_name the name of the search index
166
+ # @param [SearchRequest] search_request the request
167
+ # @param [Options::Search] options the custom options for this search request
168
+ #
169
+ # @return [SearchResult]
170
+ def search(index_name, search_request, options = Options::Search::DEFAULT)
171
+ @observability.record_operation(Observability::OP_SEARCH_QUERY, options.parent_span, self, :search) do |obs_handler|
172
+ encoded_query, encoded_req = search_request.to_backend
173
+ resp = @backend.document_search(@bucket_name, @name, index_name, encoded_query, encoded_req,
174
+ options.to_backend(show_request: false), obs_handler)
175
+ convert_search_result(resp, options)
176
+ end
177
+ end
178
+
179
+ # @return [Management::ScopeSearchIndexManager]
180
+ def search_indexes
181
+ Management::ScopeSearchIndexManager.new(@backend, @bucket_name, @name, @observability)
182
+ end
183
+
184
+ private
185
+
186
+ # @api private
187
+ def convert_search_result(resp, options)
188
+ SearchResult.new do |res|
189
+ res.meta_data = SearchMetaData.new do |meta|
190
+ meta.metrics.max_score = resp[:meta_data][:metrics][:max_score]
191
+ meta.metrics.error_partition_count = resp[:meta_data][:metrics][:error_partition_count]
192
+ meta.metrics.success_partition_count = resp[:meta_data][:metrics][:success_partition_count]
193
+ meta.metrics.took = resp[:meta_data][:metrics][:took]
194
+ meta.metrics.total_rows = resp[:meta_data][:metrics][:total_rows]
195
+ meta.errors = resp[:meta_data][:errors]
196
+ end
197
+ res.rows = resp[:rows].map do |r|
198
+ SearchRow.new do |row|
199
+ row.transcoder = options.transcoder
200
+ row.index = r[:index]
201
+ row.id = r[:id]
202
+ row.score = r[:score]
203
+ row.fragments = r[:fragments]
204
+ unless r[:locations].empty?
205
+ row.locations = SearchRowLocations.new(
206
+ r[:locations].map do |loc|
207
+ SearchRowLocation.new do |location|
208
+ location.field = loc[:field]
209
+ location.term = loc[:term]
210
+ location.position = loc[:position]
211
+ location.start_offset = loc[:start_offset]
212
+ location.end_offset = loc[:end_offset]
213
+ location.array_positions = loc[:array_positions]
214
+ end
215
+ end,
216
+ )
217
+ end
218
+ row.instance_variable_set(:@fields, r[:fields])
219
+ row.explanation = JSON.parse(r[:explanation]) if r[:explanation]
220
+ end
221
+ end
222
+ if resp[:facets]
223
+ res.facets = resp[:facets].each_with_object({}) do |(k, v), o|
224
+ facet = case options.facets[k]
225
+ when SearchFacet::SearchFacetTerm
226
+ SearchFacetResult::TermFacetResult.new do |f|
227
+ f.terms =
228
+ if v[:terms]
229
+ v[:terms].map do |t|
230
+ SearchFacetResult::TermFacetResult::TermFacet.new(t[:term], t[:count])
231
+ end
232
+ else
233
+ []
234
+ end
235
+ end
236
+ when SearchFacet::SearchFacetDateRange
237
+ SearchFacetResult::DateRangeFacetResult.new do |f|
238
+ f.date_ranges =
239
+ if v[:date_ranges]
240
+ v[:date_ranges].map do |r|
241
+ SearchFacetResult::DateRangeFacetResult::DateRangeFacet.new(r[:name], r[:count], r[:start_time], r[:end_time])
242
+ end
243
+ else
244
+ []
245
+ end
246
+ end
247
+ when SearchFacet::SearchFacetNumericRange
248
+ SearchFacetResult::NumericRangeFacetResult.new do |f|
249
+ f.numeric_ranges =
250
+ if v[:numeric_ranges]
251
+ v[:numeric_ranges].map do |r|
252
+ SearchFacetResult::NumericRangeFacetResult::NumericRangeFacet.new(r[:name], r[:count], r[:min], r[:max])
253
+ end
254
+ else
255
+ []
256
+ end
257
+ end
258
+ else
259
+ next # ignore unknown facet result
260
+ end
261
+ facet.name = v[:name]
262
+ facet.field = v[:field]
263
+ facet.total = v[:total]
264
+ facet.missing = v[:missing]
265
+ facet.other = v[:other]
266
+ o[k] = facet
267
+ end
268
+ end
269
+ end
270
+ end
271
+ end
272
+ end