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,
/Users/sergey.auseyau/code/couchbase-ruby-client/lib/couchbase/cluster.rb,
/Users/sergey.auseyau/code/couchbase-ruby-client/lib/couchbase/query_options.rb,
/Users/sergey.auseyau/code/couchbase-ruby-client/lib/couchbase/search_options.rb,
/Users/sergey.auseyau/code/couchbase-ruby-client/lib/couchbase/analytics_options.rb more...
Overview
The main entry point when connecting to a Couchbase cluster.
Defined Under Namespace
Classes: AnalyticsMetaData, AnalyticsMetrics, AnalyticsResult, AnalyticsWarning, QueryMetaData, QueryMetrics, QueryResult, QueryWarning, SearchFacet, SearchFacetResult, SearchMetaData, SearchMetrics, SearchQuery, SearchResult, SearchRow, SearchRowLocation, SearchRowLocations, SearchSort
Class Method Summary collapse
-
.connect(connection_string, *options) ⇒ Cluster
Connect to the Couchbase cluster.
Instance Method Summary collapse
- #analytics_indexes ⇒ Management::AnalyticsIndexManager
-
#analytics_query(statement, options = Options::Analytics.new) ⇒ AnalyticsResult
Performs an analytics query.
-
#bucket(name) ⇒ Bucket
Returns an instance of the Bucket.
- #buckets ⇒ Management::BucketManager
-
#diagnostics(options = Options::Diagnostics.new) ⇒ 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.new) ⇒ PingResult
Performs application-level ping requests against services in the couchbase cluster.
-
#query(statement, options = Options::Query.new) ⇒ QueryResult
Performs a query against the query (N1QL) services.
- #query_indexes ⇒ Management::QueryIndexManager
- #search_indexes ⇒ Management::SearchIndexManager
-
#search_query(index_name, query, options = Options::Search.new) ⇒ SearchResult
Performs a Full Text Search (FTS) query.
- #users ⇒ Management::UserManager
Class Method Details
.connect(connection_string, options) ⇒ Cluster .connect(connection_string, username, password, options) ⇒ Cluster
Connect to the Couchbase cluster
64 65 66 |
# File 'lib/couchbase/cluster.rb', line 64 def self.connect(connection_string, *) Cluster.new(connection_string, *) end |
Instance Method Details
#analytics_indexes ⇒ Management::AnalyticsIndexManager
280 281 282 |
# File 'lib/couchbase/cluster.rb', line 280 def analytics_indexes Management::AnalyticsIndexManager.new(@backend) end |
#analytics_query(statement, options = Options::Analytics.new) ⇒ AnalyticsResult
Performs an analytics query
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/couchbase/cluster.rb', line 133 def analytics_query(statement, = Options::Analytics.new) resp = @backend.document_analytics(statement, .to_backend) 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 |
#bucket(name) ⇒ Bucket
Returns an instance of the Bucket
73 74 75 |
# File 'lib/couchbase/cluster.rb', line 73 def bucket(name) Bucket.new(@backend, name) end |
#buckets ⇒ Management::BucketManager
270 271 272 |
# File 'lib/couchbase/cluster.rb', line 270 def buckets Management::BucketManager.new(@backend) end |
#diagnostics(options = Options::Diagnostics.new) ⇒ 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
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/couchbase/cluster.rb', line 303 def diagnostics( = Options::Diagnostics.new) 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
292 293 294 |
# File 'lib/couchbase/cluster.rb', line 292 def disconnect @backend.close end |
#ping(options = Options::Ping.new) ⇒ PingResult
Performs application-level ping requests against services in the couchbase cluster
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/couchbase/cluster.rb', line 329 def ping( = Options::Ping.new) 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.new) ⇒ QueryResult
Performs a query against the query (N1QL) services
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/couchbase/cluster.rb', line 95 def query(statement, = Options::Query.new) resp = @backend.document_query(statement, .to_backend) 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 res[:warnings] = resp[:warnings].map { |warn| QueryWarning.new(warn[:code], warn[:message]) } if resp[:warnings] end res.instance_variable_set(:@rows, resp[:rows]) end end |
#query_indexes ⇒ Management::QueryIndexManager
275 276 277 |
# File 'lib/couchbase/cluster.rb', line 275 def query_indexes Management::QueryIndexManager.new(@backend) end |
#search_indexes ⇒ Management::SearchIndexManager
285 286 287 |
# File 'lib/couchbase/cluster.rb', line 285 def search_indexes Management::SearchIndexManager.new(@backend) end |
#search_query(index_name, query, options = Options::Search.new) ⇒ SearchResult
Performs a Full Text Search (FTS) query
177 178 179 180 181 182 183 184 185 186 187 188 189 190 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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/couchbase/cluster.rb', line 177 def search_query(index_name, query, = Options::Search.new) resp = @backend.document_search(index_name, JSON.generate(query), .to_backend) SearchResult.new do |res| res. = SearchMetaData.new do || .metrics.max_score = resp[:meta_data][:metrics][:max_score] .metrics.error_partition_count = resp[:meta_data][:metrics][:error_partition_count] .metrics.success_partition_count = resp[:meta_data][:metrics][:success_partition_count] .metrics.took = resp[:meta_data][:metrics][:took] .metrics.total_rows = resp[:meta_data][:metrics][:total_rows] .errors = resp[:meta_data][:errors] end res.rows = resp[:rows].map do |r| SearchRow.new do |row| row.transcoder = .transcoder row.index = r[:index] row.id = r[:id] row.score = r[:score] row.fragments = r[:fragments] unless r[:locations].empty? row.locations = SearchRowLocations.new( r[:locations].map do |loc| SearchRowLocation.new do |location| location.field = loc[:field] location.term = loc[:term] location.position = loc[:position] location.start_offset = loc[:start_offset] location.end_offset = loc[:end_offset] location.array_positions = loc[:array_positions] end end ) end row.instance_variable_set(:@fields, r[:fields]) row.explanation = JSON.parse(r[:explanation]) if r[:explanation] end end if resp[:facets] res.facets = resp[:facets].each_with_object({}) do |(k, v), o| facet = case .facets[k] when SearchFacet::SearchFacetTerm SearchFacetResult::TermFacetResult.new do |f| f.terms = if v[:terms] v[:terms].map do |t| SearchFacetResult::TermFacetResult::TermFacet.new(t[:term], t[:count]) end else [] end end when SearchFacet::SearchFacetDateRange SearchFacetResult::DateRangeFacetResult.new do |f| f.date_ranges = if v[:date_ranges] v[:date_ranges].map do |r| SearchFacetResult::DateRangeFacetResult::DateRangeFacet.new(r[:name], r[:count], r[:start_time], r[:end_time]) end else [] end end when SearchFacet::SearchFacetNumericRange SearchFacetResult::NumericRangeFacetResult.new do |f| f.numeric_ranges = if v[:numeric_ranges] v[:numeric_ranges].map do |r| SearchFacetResult::NumericRangeFacetResult::NumericRangeFacet.new(r[:name], r[:count], r[:min], r[:max]) end else [] end end else next # ignore unknown facet result end facet.name = v[:name] facet.field = v[:field] facet.total = v[:total] facet.missing = v[:missing] facet.other = v[:other] o[k] = facet end end end end |
#users ⇒ Management::UserManager
265 266 267 |
# File 'lib/couchbase/cluster.rb', line 265 def users Management::UserManager.new(@backend) end |