Views

class couchbase.management.views.DesignDocument(name: str, views: dict[str, View], namespace: DesignDocumentNamespace | None = None, rev: str | None = None)

A design document: a named set of views.

Parameters:
  • name (str) – The name of the design document. A _design/ or dev_ prefix is removed.

  • views (dict[str, View]) – The views, keyed by name.

  • namespace (DesignDocumentNamespace, optional) – Whether the design document is in production or in

  • development.

  • rev (str, optional) – The revision of the design document.

add_view(name: str, view: View) → DesignDocument

Add a view, replacing any view of the same name.

Parameters:
  • name (str) – The name of the view.

  • view (View) – The view.

Returns:

This design document, so calls can be chained.

Return type:

DesignDocument

classmethod from_json(raw_json: dict[str, Any]) → DesignDocument

Create a design document from a dict describing it.

Parameters:

raw_json (dict[str, Any]) – The design document’s name, and optionally its rev, its namespace and its views.

Returns:

The design document.

Return type:

DesignDocument

get_view(name: str) → View | None

Get a view by name.

Parameters:

name (str) – The name of the view.

Returns:

The view, or None if the design document has no view of that name.

Return type:

View | None

property name: str

The name of the design document, without a _design/ or dev_ prefix.

property namespace: DesignDocumentNamespace | None

Whether the design document is in production or in development.

property rev: str | None

The revision of the design document, if it was read from the server.

property views: dict[str, View]

The views, keyed by name.

class couchbase.management.views.DesignDocumentNamespace(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Whether a design document is in production or in development.

A development design document indexes only part of the bucket, so its views can be tried out before they are published to production.

DEVELOPMENT = True
PRODUCTION = False
class couchbase.management.views.View(map: str, reduce: str | None = None, name: str | None = None)

A view in a design document: the map function that indexes documents, and optionally a reduce function.

Parameters:
  • map (str) – The JavaScript source of the map function.

  • reduce (str, optional) – The JavaScript source of the reduce function, or the name of a built-in one such as

  • _count.

  • name (str, optional) – Accepted and not kept: a view’s name is its key in DesignDocument.views.

classmethod from_json(json_view: dict[str, Any]) → View

Create a view from a dict holding its map and, optionally, its reduce.

Parameters:

json_view (dict[str, Any]) – The view’s fields.

Returns:

The view.

Return type:

View

property map: str

The JavaScript source of the map function.

property reduce: str | None

The JavaScript source of the reduce function, the name of a built-in one, or None.

to_json() → str

Get the view as JSON.

Returns:

The view as a JSON object holding map and, if it is set, reduce.

Return type:

str

class couchbase.management.views.ViewIndexManager(impl: ViewIndexMgmtInterface)

Performs management operations on a bucket’s view design documents.

drop_design_document(design_doc_name: str, namespace: DesignDocumentNamespace, options: DropDesignDocumentOptions | None = None, **kwargs: Unpack[DropDesignDocumentOptionsKwargs]) → None

Drops an existing design document.

Parameters:
  • design_doc_name (str) – The name of the design document.

  • namespace (DesignDocumentNamespace) – Whether the design document is in development or production.

  • options (DropDesignDocumentOptions) – Optional parameters for this operation.

  • **kwargs – keyword arguments that can be used as optional parameters for this operation.

Raises:
get_all_design_documents(namespace: DesignDocumentNamespace, options: GetAllDesignDocumentsOptions | None = None, **kwargs: Unpack[GetAllDesignDocumentsOptionsKwargs]) → Iterable[DesignDocument]

Returns every design document in a namespace.

Parameters:
  • namespace (DesignDocumentNamespace) – Whether the design document is in development or production.

  • options (GetAllDesignDocumentsOptions) – Optional parameters for this operation.

  • **kwargs – keyword arguments that can be used as optional parameters for this operation.

Returns:

The design documents.

Return type:

Iterable[DesignDocument]

Raises:

InvalidArgumentException – If the namespace is not given.

get_design_document(design_doc_name: str, namespace: DesignDocumentNamespace, options: GetDesignDocumentOptions | None = None, **kwargs: Unpack[GetDesignDocumentOptionsKwargs]) → DesignDocument

Returns a design document.

Parameters:
  • design_doc_name (str) – The name of the design document.

  • namespace (DesignDocumentNamespace) – Whether the design document is in development or production.

  • options (GetDesignDocumentOptions) – Optional parameters for this operation.

  • **kwargs – keyword arguments that can be used as optional parameters for this operation.

Returns:

The design document.

Return type:

DesignDocument

Raises:
publish_design_document(design_doc_name: str, options: PublishDesignDocumentOptions | None = None, **kwargs: Unpack[PublishDesignDocumentOptionsKwargs]) → None

Copies a design document from the development namespace to production.

The copy is a get followed by an upsert, and the timeout covers both.

Parameters:
  • design_doc_name (str) – The name of the development design document to publish.

  • options (PublishDesignDocumentOptions) – Optional parameters for this operation.

  • **kwargs – keyword arguments that can be used as optional parameters for this operation.

Raises:
upsert_design_document(design_doc_data: DesignDocument, namespace: DesignDocumentNamespace, options: UpsertDesignDocumentOptions | None = None, **kwargs: Unpack[UpsertDesignDocumentOptionsKwargs]) → None

Creates a design document, or replaces one of the same name.

Parameters:
  • design_doc_data (DesignDocument) – The design document to create or replace.

  • namespace (DesignDocumentNamespace) – Whether the design document is in development or production.

  • options (UpsertDesignDocumentOptions) – Optional parameters for this operation.

  • **kwargs – keyword arguments that can be used as optional parameters for this operation.

Raises:

InvalidArgumentException – If the design_doc_data or namespace is not given.