couchbase 3.4.0-arm64-darwin-20
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.
- checksums.yaml +7 -0
- data/LICENSE.txt +202 -0
- data/README.md +154 -0
- data/ext/extconf.rb +0 -0
- data/lib/active_support/cache/couchbase_store.rb +339 -0
- data/lib/couchbase/analytics_options.rb +107 -0
- data/lib/couchbase/authenticator.rb +65 -0
- data/lib/couchbase/binary_collection.rb +128 -0
- data/lib/couchbase/binary_collection_options.rb +24 -0
- data/lib/couchbase/bucket.rb +144 -0
- data/lib/couchbase/cluster.rb +439 -0
- data/lib/couchbase/cluster_registry.rb +44 -0
- data/lib/couchbase/collection.rb +589 -0
- data/lib/couchbase/collection_options.rb +300 -0
- data/lib/couchbase/config_profiles.rb +55 -0
- data/lib/couchbase/configuration.rb +57 -0
- data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
- data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
- data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
- data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
- data/lib/couchbase/datastructures.rb +24 -0
- data/lib/couchbase/diagnostics.rb +181 -0
- data/lib/couchbase/errors.rb +351 -0
- data/lib/couchbase/json_transcoder.rb +32 -0
- data/lib/couchbase/libcouchbase.bundle +0 -0
- data/lib/couchbase/logger.rb +85 -0
- data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
- data/lib/couchbase/management/bucket_manager.rb +436 -0
- data/lib/couchbase/management/collection_manager.rb +321 -0
- data/lib/couchbase/management/query_index_manager.rb +520 -0
- data/lib/couchbase/management/search_index_manager.rb +408 -0
- data/lib/couchbase/management/user_manager.rb +468 -0
- data/lib/couchbase/management/view_index_manager.rb +237 -0
- data/lib/couchbase/management.rb +27 -0
- data/lib/couchbase/mutation_state.rb +63 -0
- data/lib/couchbase/options.rb +2580 -0
- data/lib/couchbase/query_options.rb +120 -0
- data/lib/couchbase/railtie.rb +45 -0
- data/lib/couchbase/scope.rb +232 -0
- data/lib/couchbase/search_options.rb +1570 -0
- data/lib/couchbase/subdoc.rb +290 -0
- data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
- data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
- data/lib/couchbase/utils/time.rb +56 -0
- data/lib/couchbase/utils.rb +21 -0
- data/lib/couchbase/version.rb +23 -0
- data/lib/couchbase/view_options.rb +65 -0
- data/lib/couchbase.rb +20 -0
- data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
- metadata +101 -0
@@ -0,0 +1,120 @@
|
|
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 "json"
|
16
|
+
|
17
|
+
module Couchbase
|
18
|
+
class Cluster
|
19
|
+
class QueryResult
|
20
|
+
# @return [QueryMetaData] returns object representing additional metadata associated with this query
|
21
|
+
attr_accessor :meta_data
|
22
|
+
|
23
|
+
attr_accessor :transcoder
|
24
|
+
|
25
|
+
# Returns all rows converted using a transcoder
|
26
|
+
#
|
27
|
+
# @return [Array]
|
28
|
+
def rows(transcoder = self.transcoder)
|
29
|
+
@rows.lazy.map do |row|
|
30
|
+
if transcoder == :json
|
31
|
+
JSON.parse(row)
|
32
|
+
else
|
33
|
+
transcoder.call(row)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @yieldparam [QueryResult] self
|
39
|
+
def initialize
|
40
|
+
yield self if block_given?
|
41
|
+
@transcoder = :json
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class QueryMetaData
|
46
|
+
# @return [String] returns the request identifier string of the query request
|
47
|
+
attr_accessor :request_id
|
48
|
+
|
49
|
+
# @return [String] returns the client context identifier string set of the query request
|
50
|
+
attr_accessor :client_context_id
|
51
|
+
|
52
|
+
# @return [Symbol] returns raw query execution status as returned by the query engine
|
53
|
+
attr_accessor :status
|
54
|
+
|
55
|
+
# @return [Hash] returns the signature as returned by the query engine which is then decoded as JSON object
|
56
|
+
attr_accessor :signature
|
57
|
+
|
58
|
+
# @return [Hash] returns the profiling information returned by the query engine which is then decoded as JSON object
|
59
|
+
attr_accessor :profile
|
60
|
+
|
61
|
+
# @return [QueryMetrics] metrics as returned by the query engine, if enabled
|
62
|
+
attr_accessor :metrics
|
63
|
+
|
64
|
+
# @return [Array<QueryWarning>] list of warnings returned by the query engine
|
65
|
+
attr_accessor :warnings
|
66
|
+
|
67
|
+
# @yieldparam [QueryMetaData] self
|
68
|
+
def initialize
|
69
|
+
yield self if block_given?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class QueryMetrics
|
74
|
+
# @return [Integer] The total time taken for the request (in nanoseconds), that is the time from when the request
|
75
|
+
# was received until the results were returned.
|
76
|
+
attr_accessor :elapsed_time
|
77
|
+
|
78
|
+
# @return [Integer] The time taken for the execution of the request (in nanoseconds), that is the time from when
|
79
|
+
# query execution started until the results were returned
|
80
|
+
attr_accessor :execution_time
|
81
|
+
|
82
|
+
# @return [Integer] the total number of results selected by the engine before restriction through LIMIT clause.
|
83
|
+
attr_accessor :sort_count
|
84
|
+
|
85
|
+
# @return [Integer] The total number of objects in the results.
|
86
|
+
attr_accessor :result_count
|
87
|
+
|
88
|
+
# @return [Integer] The total number of bytes in the results.
|
89
|
+
attr_accessor :result_size
|
90
|
+
|
91
|
+
# @return [Integer] The number of mutations that were made during the request.
|
92
|
+
attr_accessor :mutation_count
|
93
|
+
|
94
|
+
# @return [Integer] The number of errors that occurred during the request.
|
95
|
+
attr_accessor :error_count
|
96
|
+
|
97
|
+
# @return [Integer] The number of warnings that occurred during the request.
|
98
|
+
attr_accessor :warning_count
|
99
|
+
|
100
|
+
# @yieldparam [QueryMetrics] self
|
101
|
+
def initialize
|
102
|
+
yield self if block_given?
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Represents a single warning returned from the query engine.
|
107
|
+
class QueryWarning
|
108
|
+
# @return [Integer]
|
109
|
+
attr_accessor :code
|
110
|
+
|
111
|
+
# @return [String]
|
112
|
+
attr_accessor :message
|
113
|
+
|
114
|
+
def initialize(code, message)
|
115
|
+
@code = code
|
116
|
+
@message = message
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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 "rails"
|
16
|
+
|
17
|
+
require "couchbase/configuration"
|
18
|
+
|
19
|
+
module Rails
|
20
|
+
module Couchbase
|
21
|
+
class Railtie < ::Rails::Railtie
|
22
|
+
def self.rescue_responses
|
23
|
+
{
|
24
|
+
"Couchbase::Error::DocumentNotFound" => :not_found,
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
config.action_dispatch.rescue_responses&.merge!(rescue_responses)
|
29
|
+
|
30
|
+
config.couchbase = ::Couchbase::Configuration.new
|
31
|
+
|
32
|
+
initializer "couchbase.load-config" do
|
33
|
+
config_path = Rails.root.join("config", "couchbase.yml")
|
34
|
+
if config_path.file?
|
35
|
+
begin
|
36
|
+
config.couchbase.load!(config_path)
|
37
|
+
rescue ::Couchbase::Error::CouchbaseError => e
|
38
|
+
puts "There is a configuration error with the current couchbase.yml"
|
39
|
+
puts e.message
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,232 @@
|
|
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
|
+
res[: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(index_name, JSON.generate(query), options.to_backend(scope_name: @name))
|
147
|
+
|
148
|
+
SearchResult.new do |res|
|
149
|
+
res.meta_data = SearchMetaData.new do |meta|
|
150
|
+
meta.metrics.max_score = resp[:meta_data][:metrics][:max_score]
|
151
|
+
meta.metrics.error_partition_count = resp[:meta_data][:metrics][:error_partition_count]
|
152
|
+
meta.metrics.success_partition_count = resp[:meta_data][:metrics][:success_partition_count]
|
153
|
+
meta.metrics.took = resp[:meta_data][:metrics][:took]
|
154
|
+
meta.metrics.total_rows = resp[:meta_data][:metrics][:total_rows]
|
155
|
+
meta.errors = resp[:meta_data][:errors]
|
156
|
+
end
|
157
|
+
res.rows = resp[:rows].map do |r|
|
158
|
+
SearchRow.new do |row|
|
159
|
+
row.transcoder = options.transcoder
|
160
|
+
row.index = r[:index]
|
161
|
+
row.id = r[:id]
|
162
|
+
row.score = r[:score]
|
163
|
+
row.fragments = r[:fragments]
|
164
|
+
unless r[:locations].empty?
|
165
|
+
row.locations = SearchRowLocations.new(
|
166
|
+
r[:locations].map do |loc|
|
167
|
+
SearchRowLocation.new do |location|
|
168
|
+
location.field = loc[:field]
|
169
|
+
location.term = loc[:term]
|
170
|
+
location.position = loc[:position]
|
171
|
+
location.start_offset = loc[:start_offset]
|
172
|
+
location.end_offset = loc[:end_offset]
|
173
|
+
location.array_positions = loc[:array_positions]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
)
|
177
|
+
end
|
178
|
+
row.instance_variable_set(:@fields, r[:fields])
|
179
|
+
row.explanation = JSON.parse(r[:explanation]) if r[:explanation]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
if resp[:facets]
|
183
|
+
res.facets = resp[:facets].each_with_object({}) do |(k, v), o|
|
184
|
+
facet = case options.facets[k]
|
185
|
+
when SearchFacet::SearchFacetTerm
|
186
|
+
SearchFacetResult::TermFacetResult.new do |f|
|
187
|
+
f.terms =
|
188
|
+
if v[:terms]
|
189
|
+
v[:terms].map do |t|
|
190
|
+
SearchFacetResult::TermFacetResult::TermFacet.new(t[:term], t[:count])
|
191
|
+
end
|
192
|
+
else
|
193
|
+
[]
|
194
|
+
end
|
195
|
+
end
|
196
|
+
when SearchFacet::SearchFacetDateRange
|
197
|
+
SearchFacetResult::DateRangeFacetResult.new do |f|
|
198
|
+
f.date_ranges =
|
199
|
+
if v[:date_ranges]
|
200
|
+
v[:date_ranges].map do |r|
|
201
|
+
SearchFacetResult::DateRangeFacetResult::DateRangeFacet.new(r[:name], r[:count], r[:start_time], r[:end_time])
|
202
|
+
end
|
203
|
+
else
|
204
|
+
[]
|
205
|
+
end
|
206
|
+
end
|
207
|
+
when SearchFacet::SearchFacetNumericRange
|
208
|
+
SearchFacetResult::NumericRangeFacetResult.new do |f|
|
209
|
+
f.numeric_ranges =
|
210
|
+
if v[:numeric_ranges]
|
211
|
+
v[:numeric_ranges].map do |r|
|
212
|
+
SearchFacetResult::NumericRangeFacetResult::NumericRangeFacet.new(r[:name], r[:count], r[:min], r[:max])
|
213
|
+
end
|
214
|
+
else
|
215
|
+
[]
|
216
|
+
end
|
217
|
+
end
|
218
|
+
else
|
219
|
+
next # ignore unknown facet result
|
220
|
+
end
|
221
|
+
facet.name = v[:name]
|
222
|
+
facet.field = v[:field]
|
223
|
+
facet.total = v[:total]
|
224
|
+
facet.missing = v[:missing]
|
225
|
+
facet.other = v[:other]
|
226
|
+
o[k] = facet
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|