Class: Couchbase::Management::ViewIndexManager Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/management/view_index_manager.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/management/view_index_manager.rb

Overview

Deprecated.

Views are deprecated in Couchbase Server 7.0+, and will be removed from a future server version. Views are not compatible with the Magma storage engine. Instead of views, use indexes and queries using the Index Service (GSI) and the Query Service (SQL++).

The View Index Manager interface contains the means for managing design documents used for views.

A design document belongs to either the “development” or “production” namespace. A development document has a name that starts with “dev_”. This is an implementation detail we’ve chosen to hide from consumers of this API. Document names presented to the user (returned from the “get” and “get all” methods, for example) always have the “dev_” prefix stripped.

Whenever the user passes a design document name to any method of this API, the user may refer to the document using the “dev_” prefix regardless of whether the user is referring to a development document or production document. The “dev_” prefix is always stripped from user input, and the actual document name passed to the server is determined by the “namespace” argument.

All methods (except publish) have a required “namespace” argument indicating whether the operation targets a development document or a production document. The type of this argument is [Symbol] with allowed values :production and :development.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend, bucket_name, observability) ⇒ ViewIndexManager

Returns a new instance of ViewIndexManager.

Parameters:



154
155
156
157
158
# File 'lib/couchbase/management/view_index_manager.rb', line 154

def initialize(backend, bucket_name, observability)
  @backend = backend
  @bucket_name = bucket_name
  @observability = observability
end

Instance Attribute Details

#bucket_nameString

Returns name of the bucket.

Returns:

  • (String)

    name of the bucket



149
150
151
# File 'lib/couchbase/management/view_index_manager.rb', line 149

def bucket_name
  @bucket_name
end

Instance Method Details

#drop_design_document(name, namespace, options = Options::View::DropDesignDocument::DEFAULT) ⇒ void

This method returns an undefined value.

Removes the design document

Parameters:

  • name (String)

    design document name

  • namespace (:production, :development)

    the namespace

  • options (Options::View::DropDesignDocument) (defaults to: Options::View::DropDesignDocument::DEFAULT)

Raises:



222
223
224
225
226
# File 'lib/couchbase/management/view_index_manager.rb', line 222

def drop_design_document(name, namespace, options = Options::View::DropDesignDocument::DEFAULT)
  @observability.record_operation(Observability::OP_VM_DROP_DESIGN_DOCUMENT, options.parent_span, self, :views) do |obs_handler|
    @backend.view_index_drop(@bucket_name, name, namespace, options.timeout, obs_handler)
  end
end

#get_all_design_documents(namespace, options = Options::View::GetAllDesignDocuments::DEFAULT) ⇒ Array<DesignDocument>

Fetches all design documents from the server

Parameters:

Returns:



182
183
184
185
186
187
188
189
# File 'lib/couchbase/management/view_index_manager.rb', line 182

def get_all_design_documents(namespace, options = Options::View::GetAllDesignDocuments::DEFAULT)
  @observability.record_operation(Observability::OP_VM_GET_ALL_DESIGN_DOCUMENTS, options.parent_span, self, :views) do |obs_handler|
    resp = @backend.view_index_get_all(@bucket_name, namespace, options.timeout, obs_handler)
    resp.map do |entry|
      extract_design_document(entry)
    end
  end
end

#get_design_document(name, namespace, options = Options::View::GetDesignDocument::DEFAULT) ⇒ DesignDocument

Fetches a design document from the server

Parameters:

  • name (String)

    the name of the design document

  • namespace (:production, :development)

    the namespace

  • options (Options::View::GetDesignDocument) (defaults to: Options::View::GetDesignDocument::DEFAULT)

Returns:

Raises:



169
170
171
172
173
174
# File 'lib/couchbase/management/view_index_manager.rb', line 169

def get_design_document(name, namespace, options = Options::View::GetDesignDocument::DEFAULT)
  @observability.record_operation(Observability::OP_VM_GET_DESIGN_DOCUMENT, options.parent_span, self, :views) do |obs_handler|
    resp = @backend.view_index_get(@bucket_name, name, namespace, options.timeout, obs_handler)
    extract_design_document(resp)
  end
end

#publish_design_document(name, options = Options::View::PublishDesignDocument::DEFAULT) ⇒ void

This method returns an undefined value.

Publishes the design document.

This method is equivalent to getting a document from the development namespace and upserting it to the production namespace.

Parameters:

Raises:



240
241
242
243
244
245
246
247
# File 'lib/couchbase/management/view_index_manager.rb', line 240

def publish_design_document(name, options = Options::View::PublishDesignDocument::DEFAULT)
  @observability.record_operation(Observability::OP_VM_PUBLISH_DESIGN_DOCUMENT, options.parent_span, self, :views) do |obs_handler|
    document = get_design_document(name, :development,
                                   Options::View::GetDesignDocument.new(timeout: options.timeout, parent_span: obs_handler.op_span))
    upsert_design_document(document, :production,
                           Options::View::UpsertDesignDocument.new(timeout: options.timeout, parent_span: obs_handler.op_span))
  end
end

#upsert_design_document(document, namespace, options = Options::View::UpsertDesignDocument::DEFAULT) ⇒ void

This method returns an undefined value.

Updates or inserts the design document

Parameters:



198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/couchbase/management/view_index_manager.rb', line 198

def upsert_design_document(document, namespace, options = Options::View::UpsertDesignDocument::DEFAULT)
  @observability.record_operation(Observability::OP_VM_UPSERT_DESIGN_DOCUMENT, options.parent_span, self, :views) do |obs_handler|
    @backend.view_index_upsert(@bucket_name, {
      name: document.name,
      views: document.views.map do |name, view|
        {
          name: name,
          map: view.map_function,
          reduce: view.reduce_function,
        }
      end,
    }, namespace, options.timeout, obs_handler)
  end
end