Class: Couchbase::Scope
- Inherits:
-
Object
- Object
- Couchbase::Scope
- Defined in:
- lib/couchbase/scope.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/scope.rb
Overview
The scope identifies a group of collections and allows high application density as a result.
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#analytics_query(statement, options = Options::Analytics::DEFAULT) ⇒ AnalyticsResult
Performs an analytics query.
-
#collection(collection_name) ⇒ Collection
Opens the default collection for this scope.
-
#initialize(backend, bucket_name, scope_name, observability) ⇒ Scope
constructor
A new instance of Scope.
-
#query(statement, options = Options::Query::DEFAULT) ⇒ QueryResult
Performs a query against the query (N1QL) services.
-
#search(index_name, search_request, options = Options::Search::DEFAULT) ⇒ SearchResult
Performs a request against the Full Text Search (FTS) service.
- #search_indexes ⇒ Management::ScopeSearchIndexManager
-
#search_query(index_name, query, options = Options::Search::DEFAULT) ⇒ SearchResult
Performs a Full Text Search (FTS) query.
Constructor Details
#initialize(backend, bucket_name, scope_name, observability) ⇒ Scope
Returns a new instance of Scope.
32 33 34 35 36 37 |
# File 'lib/couchbase/scope.rb', line 32 def initialize(backend, bucket_name, scope_name, observability) @backend = backend @bucket_name = bucket_name @name = scope_name @observability = observability end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
24 25 26 |
# File 'lib/couchbase/scope.rb', line 24 def bucket_name @bucket_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/couchbase/scope.rb', line 25 def name @name end |
Instance Method Details
#analytics_query(statement, options = Options::Analytics::DEFAULT) ⇒ AnalyticsResult
Performs an analytics query
The query will be implicitly scoped using current bucket and scope names.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/couchbase/scope.rb', line 107 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(scope_name: @name, bucket_name: @bucket_name)) Cluster::AnalyticsResult.new do |res| res.transcoder = .transcoder res. = Cluster::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 = Cluster::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| Cluster::AnalyticsWarning.new(warn[:code], warn[:message]) } if resp[:warnings] end res.instance_variable_set(:@rows, resp[:rows]) end end end |
#collection(collection_name) ⇒ Collection
Opens the default collection for this scope
44 45 46 |
# File 'lib/couchbase/scope.rb', line 44 def collection(collection_name) Collection.new(@backend, @bucket_name, @name, collection_name, @observability) end |
#query(statement, options = Options::Query::DEFAULT) ⇒ QueryResult
Performs a query against the query (N1QL) services.
The query will be implicitly scoped using current bucket and scope names.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/couchbase/scope.rb', line 63 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(scope_name: @name, bucket_name: @bucket_name), obs_handler) Cluster::QueryResult.new do |res| res. = Cluster::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 = Cluster::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| Cluster::QueryWarning.new(warn[:code], warn[:message]) } if resp[:warnings] end res.instance_variable_set(:@rows, resp[:rows]) end end end |
#search(index_name, search_request, options = Options::Search::DEFAULT) ⇒ SearchResult
Performs a request against the Full Text Search (FTS) service.
170 171 172 173 174 175 176 177 |
# File 'lib/couchbase/scope.rb', line 170 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(@bucket_name, @name, index_name, encoded_query, encoded_req, .to_backend(show_request: false), obs_handler) convert_search_result(resp, ) end end |
#search_indexes ⇒ Management::ScopeSearchIndexManager
180 181 182 |
# File 'lib/couchbase/scope.rb', line 180 def search_indexes Management::ScopeSearchIndexManager.new(@backend, @bucket_name, @name, @observability) end |
#search_query(index_name, query, options = Options::Search::DEFAULT) ⇒ SearchResult
Performs a Full Text Search (FTS) query
156 157 158 159 160 161 |
# File 'lib/couchbase/scope.rb', line 156 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(@bucket_name, @name, index_name, JSON.generate(query), {}, .to_backend, obs_handler) convert_search_result(resp, ) end end |