Class: Couchbase::Cluster
- Inherits:
-
Object
- Object
- Couchbase::Cluster
- Defined in:
- lib/couchbase/cluster.rb,
lib/couchbase/query_options.rb,
lib/couchbase/search_options.rb,
lib/couchbase/analytics_options.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/cluster.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/query_options.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/search_options.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/analytics_options.rb
Overview
The main entry point when connecting to a Couchbase cluster.
Defined Under Namespace
Classes: AnalyticsMetaData, AnalyticsMetrics, AnalyticsResult, AnalyticsWarning, QueryMetaData, QueryMetrics, QueryResult, QueryWarning
Constant Summary collapse
- SearchQuery =
Couchbase::SearchQuery
- SearchSort =
Couchbase::SearchSort
- SearchFacet =
Couchbase::SearchFacet
- SearchRowLocation =
Couchbase::SearchRowLocation
- SearchRowLocations =
Couchbase::SearchRowLocations
- SearchFacetResult =
Couchbase::SearchFacetResult
- SearchRow =
Couchbase::SearchRow
- SearchResult =
Couchbase::SearchResult
- SearchMetaData =
Couchbase::SearchMetaData
- SearchMetrics =
Couchbase::SearchMetrics
Class Method Summary collapse
-
.connect(connection_string_or_config, *options) ⇒ Cluster
Connect to the Couchbase cluster.
Instance Method Summary collapse
- #analytics_indexes ⇒ Management::AnalyticsIndexManager
-
#analytics_query(statement, options = Options::Analytics::DEFAULT) ⇒ AnalyticsResult
Performs an analytics query.
-
#bucket(name) ⇒ Bucket
Returns an instance of the Bucket.
- #buckets ⇒ Management::BucketManager
-
#diagnostics(options = Options::Diagnostics::DEFAULT) ⇒ DiagnosticsResult
Creates diagnostic report that can be used to determine the health of the network connections.
-
#disconnect ⇒ void
Closes all connections to services and free allocated resources.
-
#ping(options = Options::Ping::DEFAULT) ⇒ PingResult
Performs application-level ping requests against services in the couchbase cluster.
-
#query(statement, options = Options::Query::DEFAULT) ⇒ QueryResult
Performs a query against the query (N1QL) services.
- #query_indexes ⇒ Management::QueryIndexManager
-
#search(index_name, search_request, options = Options::Search::DEFAULT) ⇒ SearchResult
Performs a request against the Full Text Search (FTS) service.
- #search_indexes ⇒ Management::SearchIndexManager
-
#search_query(index_name, query, options = Options::Search::DEFAULT) ⇒ SearchResult
Performs a Full Text Search (FTS) query.
-
#update_authenticator(authenticator) ⇒ Object
Updates the authenticator used for this cluster connection.
- #users ⇒ Management::UserManager
Class Method Details
.connect(connection_string_or_config, options) ⇒ Cluster .connect(connection_string_or_config, username, password, options) ⇒ Cluster
The couchbase2:// scheme is currently at stability uncommitted
Connect to the Couchbase cluster
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/couchbase/cluster.rb', line 77 def self.connect(connection_string_or_config, *) connection_string = if connection_string_or_config.is_a?(Configuration) connection_string_or_config.connection_string else connection_string_or_config end if connection_string =~ /\Acouchbases?:\/\/.*\z/i || !connection_string.include?("://") Cluster.new(connection_string_or_config, *) else ClusterRegistry.instance.connect(connection_string_or_config, *) end end |
Instance Method Details
#analytics_indexes ⇒ Management::AnalyticsIndexManager
278 279 280 |
# File 'lib/couchbase/cluster.rb', line 278 def analytics_indexes Management::AnalyticsIndexManager.new(@backend, @observability) end |
#analytics_query(statement, options = Options::Analytics::DEFAULT) ⇒ AnalyticsResult
Performs an analytics query
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/couchbase/cluster.rb', line 191 def analytics_query(statement, = Options::Analytics::DEFAULT) @observability.record_operation(Observability::OP_ANALYTICS_QUERY, .parent_span, self, :analytics) do |obs_handler| obs_handler.add_query_statement(statement, ) resp = @backend.document_analytics(statement, .to_backend, obs_handler) AnalyticsResult.new do |res| res.transcoder = .transcoder res. = AnalyticsMetaData.new do || .status = resp[:meta][:status] .request_id = resp[:meta][:request_id] .client_context_id = resp[:meta][:client_context_id] .signature = JSON.parse(resp[:meta][:signature]) if resp[:meta][:signature] .profile = JSON.parse(resp[:meta][:profile]) if resp[:meta][:profile] .metrics = AnalyticsMetrics.new do |metrics| if resp[:meta][:metrics] metrics.elapsed_time = resp[:meta][:metrics][:elapsed_time] metrics.execution_time = resp[:meta][:metrics][:execution_time] metrics.result_count = resp[:meta][:metrics][:result_count] metrics.result_size = resp[:meta][:metrics][:result_size] metrics.error_count = resp[:meta][:metrics][:error_count] metrics.warning_count = resp[:meta][:metrics][:warning_count] metrics.processed_objects = resp[:meta][:metrics][:processed_objects] end end res[:warnings] = resp[:warnings].map { |warn| AnalyticsWarning.new(warn[:code], warn[:message]) } if resp[:warnings] end res.instance_variable_set(:@rows, resp[:rows]) end end end |
#bucket(name) ⇒ Bucket
Returns an instance of the Bucket
95 96 97 |
# File 'lib/couchbase/cluster.rb', line 95 def bucket(name) Bucket.new(@backend, name, @observability) end |
#buckets ⇒ Management::BucketManager
268 269 270 |
# File 'lib/couchbase/cluster.rb', line 268 def buckets Management::BucketManager.new(@backend, @observability) end |
#diagnostics(options = Options::Diagnostics::DEFAULT) ⇒ DiagnosticsResult
Creates diagnostic report that can be used to determine the health of the network connections.
It does not proactively perform any I/O against the network
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/couchbase/cluster.rb', line 302 def diagnostics( = Options::Diagnostics::DEFAULT) resp = @backend.diagnostics(.report_id) DiagnosticsResult.new do |res| res.version = resp[:version] res.id = resp[:id] res.sdk = resp[:sdk] resp[:services].each do |type, svcs| res.services[type] = svcs.map do |svc| DiagnosticsResult::ServiceInfo.new do |info| info.id = svc[:id] info.state = svc[:state] info.last_activity_us = svc[:last_activity_us] info.remote = svc[:remote] info.local = svc[:local] info.details = svc[:details] end end end end end |
#disconnect ⇒ void
This method returns an undefined value.
Closes all connections to services and free allocated resources
290 291 292 293 |
# File 'lib/couchbase/cluster.rb', line 290 def disconnect @backend.close @observability.close end |
#ping(options = Options::Ping::DEFAULT) ⇒ PingResult
Performs application-level ping requests against services in the couchbase cluster
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/couchbase/cluster.rb', line 328 def ping( = Options::Ping::DEFAULT) resp = @backend.ping(nil, .to_backend) PingResult.new do |res| res.version = resp[:version] res.id = resp[:id] res.sdk = resp[:sdk] resp[:services].each do |type, svcs| res.services[type] = svcs.map do |svc| PingResult::ServiceInfo.new do |info| info.id = svc[:id] info.state = svc[:state] info.latency = svc[:latency] info.remote = svc[:remote] info.local = svc[:local] info.error = svc[:error] end end end end end |
#query(statement, options = Options::Query::DEFAULT) ⇒ QueryResult
Performs a query against the query (N1QL) services
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/couchbase/cluster.rb', line 149 def query(statement, = Options::Query::DEFAULT) @observability.record_operation(Observability::OP_QUERY, .parent_span, self, :query) do |obs_handler| obs_handler.add_query_statement(statement, ) resp = @backend.document_query(statement, .to_backend, obs_handler) QueryResult.new do |res| res. = QueryMetaData.new do || .status = resp[:meta][:status] .request_id = resp[:meta][:request_id] .client_context_id = resp[:meta][:client_context_id] .signature = JSON.parse(resp[:meta][:signature]) if resp[:meta][:signature] .profile = JSON.parse(resp[:meta][:profile]) if resp[:meta][:profile] .metrics = QueryMetrics.new do |metrics| if resp[:meta][:metrics] metrics.elapsed_time = resp[:meta][:metrics][:elapsed_time] metrics.execution_time = resp[:meta][:metrics][:execution_time] metrics.sort_count = resp[:meta][:metrics][:sort_count] metrics.result_count = resp[:meta][:metrics][:result_count] metrics.result_size = resp[:meta][:metrics][:result_size] metrics.mutation_count = resp[:meta][:metrics][:mutation_count] metrics.error_count = resp[:meta][:metrics][:error_count] metrics.warning_count = resp[:meta][:metrics][:warning_count] end end .warnings = resp[:warnings].map { |warn| QueryWarning.new(warn[:code], warn[:message]) } if resp[:warnings] end res.instance_variable_set(:@rows, resp[:rows]) end end end |
#query_indexes ⇒ Management::QueryIndexManager
273 274 275 |
# File 'lib/couchbase/cluster.rb', line 273 def query_indexes Management::QueryIndexManager.new(@backend, @observability) end |
#search(index_name, search_request, options = Options::Search::DEFAULT) ⇒ SearchResult
Performs a request against the Full Text Search (FTS) service.
253 254 255 256 257 258 259 260 |
# File 'lib/couchbase/cluster.rb', line 253 def search(index_name, search_request, = Options::Search::DEFAULT) @observability.record_operation(Observability::OP_SEARCH_QUERY, .parent_span, self, :search) do |obs_handler| encoded_query, encoded_req = search_request.to_backend resp = @backend.document_search(nil, nil, index_name, encoded_query, encoded_req, .to_backend(show_request: false), obs_handler) convert_search_result(resp, ) end end |
#search_indexes ⇒ Management::SearchIndexManager
283 284 285 |
# File 'lib/couchbase/cluster.rb', line 283 def search_indexes Management::SearchIndexManager.new(@backend, @observability) end |
#search_query(index_name, query, options = Options::Search::DEFAULT) ⇒ SearchResult
Performs a Full Text Search (FTS) query
239 240 241 242 243 244 |
# File 'lib/couchbase/cluster.rb', line 239 def search_query(index_name, query, = Options::Search::DEFAULT) @observability.record_operation(Observability::OP_SEARCH_QUERY, .parent_span, self, :search) do |obs_handler| resp = @backend.document_search(nil, nil, index_name, JSON.generate(query), {}, .to_backend, obs_handler) convert_search_result(resp, ) end end |
#update_authenticator(authenticator) ⇒ Object
Updates the authenticator used for this cluster connection
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/couchbase/cluster.rb', line 102 def update_authenticator(authenticator) credentials = {} case authenticator when PasswordAuthenticator credentials[:username] = authenticator.username raise ArgumentError, "missing username" unless credentials[:username] credentials[:password] = authenticator.password raise ArgumentError, "missing password" unless credentials[:password] when CertificateAuthenticator credentials[:certificate_path] = authenticator.certificate_path raise ArgumentError, "missing certificate path" unless credentials[:certificate_path] credentials[:key_path] = authenticator.key_path raise ArgumentError, "missing key path" unless credentials[:key_path] when JWTAuthenticator credentials[:jwt] = authenticator.token raise ArgumentError, "missing token" unless credentials[:jwt] else raise ArgumentError, "argument must be an authenticator" end @backend.update_credentials(credentials) end |
#users ⇒ Management::UserManager
263 264 265 |
# File 'lib/couchbase/cluster.rb', line 263 def users Management::UserManager.new(@backend, @observability) end |