couchbase 3.5.0-arm64-darwin-23

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,256 @@
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/collection"
16
+ require "couchbase/query_options"
17
+ require "couchbase/analytics_options"
18
+
19
+ module Couchbase
20
+ # The scope identifies a group of collections and allows high application density as a result.
21
+ class Scope
22
+ attr_reader :bucket_name
23
+ attr_reader :name
24
+
25
+ alias inspect to_s
26
+
27
+ # @param [Couchbase::Backend] backend
28
+ # @param [String] bucket_name name of the bucket
29
+ # @param [String] scope_name name of the scope
30
+ def initialize(backend, bucket_name, scope_name)
31
+ @backend = backend
32
+ @bucket_name = bucket_name
33
+ @name = scope_name
34
+ end
35
+
36
+ # Opens the default collection for this scope
37
+ #
38
+ # @param [String] collection_name name of the collection
39
+ #
40
+ # @return [Collection]
41
+ def collection(collection_name)
42
+ Collection.new(@backend, @bucket_name, @name, collection_name)
43
+ end
44
+
45
+ # Performs a query against the query (N1QL) services.
46
+ #
47
+ # The query will be implicitly scoped using current bucket and scope names.
48
+ #
49
+ # @see Options::Query#scope_qualifier
50
+ # @see Cluster#query
51
+ #
52
+ # @param [String] statement the N1QL query statement
53
+ # @param [Options::Query] options the custom options for this query
54
+ #
55
+ # @example Select first ten hotels from travel sample dataset
56
+ # scope.query("SELECT * FROM `travel-sample` WHERE type = $type LIMIT 10",
57
+ # Options::Query(named_parameters: {type: "hotel"}, metrics: true))
58
+ #
59
+ # @return [QueryResult]
60
+ def query(statement, options = Options::Query::DEFAULT)
61
+ resp = @backend.document_query(statement, options.to_backend(scope_name: @name, bucket_name: @bucket_name))
62
+
63
+ Cluster::QueryResult.new do |res|
64
+ res.meta_data = Cluster::QueryMetaData.new do |meta|
65
+ meta.status = resp[:meta][:status]
66
+ meta.request_id = resp[:meta][:request_id]
67
+ meta.client_context_id = resp[:meta][:client_context_id]
68
+ meta.signature = JSON.parse(resp[:meta][:signature]) if resp[:meta][:signature]
69
+ meta.profile = JSON.parse(resp[:meta][:profile]) if resp[:meta][:profile]
70
+ meta.metrics = Cluster::QueryMetrics.new do |metrics|
71
+ if resp[:meta][:metrics]
72
+ metrics.elapsed_time = resp[:meta][:metrics][:elapsed_time]
73
+ metrics.execution_time = resp[:meta][:metrics][:execution_time]
74
+ metrics.sort_count = resp[:meta][:metrics][:sort_count]
75
+ metrics.result_count = resp[:meta][:metrics][:result_count]
76
+ metrics.result_size = resp[:meta][:metrics][:result_size]
77
+ metrics.mutation_count = resp[:meta][:metrics][:mutation_count]
78
+ metrics.error_count = resp[:meta][:metrics][:error_count]
79
+ metrics.warning_count = resp[:meta][:metrics][:warning_count]
80
+ end
81
+ end
82
+ meta.warnings = resp[:warnings].map { |warn| Cluster::QueryWarning.new(warn[:code], warn[:message]) } if resp[:warnings]
83
+ end
84
+ res.instance_variable_set(:@rows, resp[:rows])
85
+ end
86
+ end
87
+
88
+ # Performs an analytics query
89
+ #
90
+ # The query will be implicitly scoped using current bucket and scope names.
91
+ #
92
+ # @param [String] statement the N1QL query statement
93
+ # @param [Options::Analytics] options the custom options for this query
94
+ #
95
+ # @example Select name of the given user
96
+ # scope.analytics_query("SELECT u.name AS uname FROM GleambookUsers u WHERE u.id = $user_id ",
97
+ # Options::Analytics(named_parameters: {user_id: 2}))
98
+ #
99
+ # @return [AnalyticsResult]
100
+ def analytics_query(statement, options = Options::Analytics::DEFAULT)
101
+ resp = @backend.document_analytics(statement, options.to_backend(scope_name: @name, bucket_name: @bucket_name))
102
+
103
+ Cluster::AnalyticsResult.new do |res|
104
+ res.transcoder = options.transcoder
105
+ res.meta_data = Cluster::AnalyticsMetaData.new do |meta|
106
+ meta.status = resp[:meta][:status]
107
+ meta.request_id = resp[:meta][:request_id]
108
+ meta.client_context_id = resp[:meta][:client_context_id]
109
+ meta.signature = JSON.parse(resp[:meta][:signature]) if resp[:meta][:signature]
110
+ meta.profile = JSON.parse(resp[:meta][:profile]) if resp[:meta][:profile]
111
+ meta.metrics = Cluster::AnalyticsMetrics.new do |metrics|
112
+ if resp[:meta][:metrics]
113
+ metrics.elapsed_time = resp[:meta][:metrics][:elapsed_time]
114
+ metrics.execution_time = resp[:meta][:metrics][:execution_time]
115
+ metrics.result_count = resp[:meta][:metrics][:result_count]
116
+ metrics.result_size = resp[:meta][:metrics][:result_size]
117
+ metrics.error_count = resp[:meta][:metrics][:error_count]
118
+ metrics.warning_count = resp[:meta][:metrics][:warning_count]
119
+ metrics.processed_objects = resp[:meta][:metrics][:processed_objects]
120
+ end
121
+ end
122
+ res[:warnings] = resp[:warnings].map { |warn| Cluster::AnalyticsWarning.new(warn[:code], warn[:message]) } if resp[:warnings]
123
+ end
124
+ res.instance_variable_set(:@rows, resp[:rows])
125
+ end
126
+ end
127
+
128
+ # Performs a Full Text Search (FTS) query
129
+ #
130
+ # @param [String] index_name the name of the search index
131
+ # @param [SearchQuery] query the query tree
132
+ # @param [Options::Search] options the query tree
133
+ #
134
+ # @example Return first 10 results of "hop beer" query and request highlighting
135
+ # cluster.search_query("travel_index", Cluster::SearchQuery.match_phrase("green"),
136
+ # Options::Search(
137
+ # limit: 10,
138
+ # collections: ["landmark", "hotel"]
139
+ # fields: %w[name],
140
+ # highlight_style: :html,
141
+ # highlight_fields: %w[name description]
142
+ # ))
143
+ #
144
+ # @return [SearchResult]
145
+ def search_query(index_name, query, options = Options::Search::DEFAULT)
146
+ resp = @backend.document_search(@bucket_name, @name, index_name, JSON.generate(query), {}, options.to_backend)
147
+ convert_search_result(resp, options)
148
+ end
149
+
150
+ # Performs a request against the Full Text Search (FTS) service.
151
+ #
152
+ # @param [String] index_name the name of the search index
153
+ # @param [SearchRequest] search_request the request
154
+ # @param [Options::Search] options the custom options for this search request
155
+ #
156
+ # @return [SearchResult]
157
+ def search(index_name, search_request, options = Options::Search::DEFAULT)
158
+ encoded_query, encoded_req = search_request.to_backend
159
+ resp = @backend.document_search(@bucket_name, @name, index_name, encoded_query, encoded_req, options.to_backend(show_request: false))
160
+ convert_search_result(resp, options)
161
+ end
162
+
163
+ # @return [Management::ScopeSearchIndexManager]
164
+ def search_indexes
165
+ Management::ScopeSearchIndexManager.new(@backend, @bucket_name, @name)
166
+ end
167
+
168
+ private
169
+
170
+ # @api private
171
+ def convert_search_result(resp, options)
172
+ SearchResult.new do |res|
173
+ res.meta_data = SearchMetaData.new do |meta|
174
+ meta.metrics.max_score = resp[:meta_data][:metrics][:max_score]
175
+ meta.metrics.error_partition_count = resp[:meta_data][:metrics][:error_partition_count]
176
+ meta.metrics.success_partition_count = resp[:meta_data][:metrics][:success_partition_count]
177
+ meta.metrics.took = resp[:meta_data][:metrics][:took]
178
+ meta.metrics.total_rows = resp[:meta_data][:metrics][:total_rows]
179
+ meta.errors = resp[:meta_data][:errors]
180
+ end
181
+ res.rows = resp[:rows].map do |r|
182
+ SearchRow.new do |row|
183
+ row.transcoder = options.transcoder
184
+ row.index = r[:index]
185
+ row.id = r[:id]
186
+ row.score = r[:score]
187
+ row.fragments = r[:fragments]
188
+ unless r[:locations].empty?
189
+ row.locations = SearchRowLocations.new(
190
+ r[:locations].map do |loc|
191
+ SearchRowLocation.new do |location|
192
+ location.field = loc[:field]
193
+ location.term = loc[:term]
194
+ location.position = loc[:position]
195
+ location.start_offset = loc[:start_offset]
196
+ location.end_offset = loc[:end_offset]
197
+ location.array_positions = loc[:array_positions]
198
+ end
199
+ end
200
+ )
201
+ end
202
+ row.instance_variable_set(:@fields, r[:fields])
203
+ row.explanation = JSON.parse(r[:explanation]) if r[:explanation]
204
+ end
205
+ end
206
+ if resp[:facets]
207
+ res.facets = resp[:facets].each_with_object({}) do |(k, v), o|
208
+ facet = case options.facets[k]
209
+ when SearchFacet::SearchFacetTerm
210
+ SearchFacetResult::TermFacetResult.new do |f|
211
+ f.terms =
212
+ if v[:terms]
213
+ v[:terms].map do |t|
214
+ SearchFacetResult::TermFacetResult::TermFacet.new(t[:term], t[:count])
215
+ end
216
+ else
217
+ []
218
+ end
219
+ end
220
+ when SearchFacet::SearchFacetDateRange
221
+ SearchFacetResult::DateRangeFacetResult.new do |f|
222
+ f.date_ranges =
223
+ if v[:date_ranges]
224
+ v[:date_ranges].map do |r|
225
+ SearchFacetResult::DateRangeFacetResult::DateRangeFacet.new(r[:name], r[:count], r[:start_time], r[:end_time])
226
+ end
227
+ else
228
+ []
229
+ end
230
+ end
231
+ when SearchFacet::SearchFacetNumericRange
232
+ SearchFacetResult::NumericRangeFacetResult.new do |f|
233
+ f.numeric_ranges =
234
+ if v[:numeric_ranges]
235
+ v[:numeric_ranges].map do |r|
236
+ SearchFacetResult::NumericRangeFacetResult::NumericRangeFacet.new(r[:name], r[:count], r[:min], r[:max])
237
+ end
238
+ else
239
+ []
240
+ end
241
+ end
242
+ else
243
+ next # ignore unknown facet result
244
+ end
245
+ facet.name = v[:name]
246
+ facet.field = v[:field]
247
+ facet.total = v[:total]
248
+ facet.missing = v[:missing]
249
+ facet.other = v[:other]
250
+ o[k] = facet
251
+ end
252
+ end
253
+ end
254
+ end
255
+ end
256
+ end