Scope

class txcouchbase.scope.Scope(bucket: Bucket, scope_name: str)

A scope in a bucket: its collections, and the queries and searches run against it.

Get one from scope().

Parameters:
  • bucket (Bucket) – The bucket the scope belongs to.

  • scope_name (str) – The name of the scope.

analytics_query(statement: str, *options: AnalyticsOptions | str | int | float | bool | None | Mapping[str, Any] | Sequence[Any], **kwargs: Any) → Deferred[AnalyticsResult]

Executes an analaytics query against the scope.

Note

The analytics query is sent when this is called, and the Deferred fires once the core has buffered the response, so iterating the AnalyticsResult does not block the reactor.

See also

Parameters:
  • statement (str) – The analytics SQL++ statement to execute.

  • options (AnalyticsOptions) – Optional parameters for the analytics query operation.

  • **kwargs – keyword arguments that can be used in place or to override provided AnalyticsOptions. A keyword that is not one of its options is sent as a named parameter; prefer AnalyticsOptions(named_parameters=...), which cannot collide with an option name.

Returns:

An instance of a AnalyticsResult which provides access to iterate over the analytics query results and access metadata and metrics about the analytics query.

Return type:

Deferred[AnalyticsResult]

property bucket_name: str

The name of the bucket this scope belongs to.

collection(name: str) → Collection

Creates a Collection instance of the specified collection.

Parameters:

name (str) – Name of the collection to reference.

Returns:

A Collection instance of the specified collection.

Return type:

Collection

static default_name() → str

The name of a bucket’s default scope.

property name: str

The name of this scope.

query(statement: str, *options: QueryOptions | str | int | float | bool | None | Mapping[str, Any] | Sequence[Any], **kwargs: Any) → Deferred[QueryResult]

Executes a N1QL query against the scope.

Note

The query is sent when this is called, and the Deferred fires once the core has buffered the response, so iterating the QueryResult does not block the reactor.

Note

Scope-level queries are only supported on Couchbase Server versions that support scopes and collections.

See also

Parameters:
  • statement (str) – The N1QL statement to execute.

  • options (QueryOptions) – Optional parameters for the query operation.

  • **kwargs – keyword arguments that can be used in place or to override provided QueryOptions. A keyword that is not one of its options is sent as a named parameter; prefer QueryOptions(named_parameters=...), which cannot collide with an option name.

Returns:

An instance of a QueryResult which provides access to iterate over the query results and access metadata and metrics about the query.

Return type:

Deferred[QueryResult]

search(index: str, request: SearchRequest | SearchQuery, options: SearchOptions | None = None, **kwargs: Unpack[SearchOptionsKwargs]) → Deferred[SearchResult]

Executes an search against the scope.

Note

The search is sent when this is called, and the Deferred fires once the core has buffered the response, so iterating the SearchResult does not block the reactor.

See also

Parameters:
  • index (str) – Name of the search index to use.

  • request (SearchRequest | SearchQuery) –

    Type of search request to perform.

    Deprecated since version 4.7.0: Passing a SearchQuery is deprecated; wrap it with create() instead.

  • options (SearchOptions) – Optional parameters for the search query operation.

  • **kwargs – keyword arguments that can be used in place or to override provided SearchOptions

Returns:

An instance of a SearchResult which provides access to iterate over the search query results and access metadata and metrics about the search query.

Return type:

Deferred[SearchResult]

search_indexes() → ScopeSearchIndexManager

Get a manager for the search indexes of this scope.

Returns:

A ScopeSearchIndexManager instance.

Return type:

ScopeSearchIndexManager

search_query(index: str, query: SearchQuery, options: SearchOptions | None = None, **kwargs: Unpack[SearchOptionsKwargs]) → Deferred[SearchResult]

Executes an search query against the scope.

Deprecated since version 4.1.11: Use search() instead.

Note

The search query is sent when this is called, and the Deferred fires once the core has buffered the response, so iterating the SearchResult does not block the reactor.

Parameters:
  • index (str) – Name of the search query to use.

  • query (SearchQuery) – Type of search query to perform.

  • options (SearchOptions) – Optional parameters for the search query operation.

  • **kwargs – keyword arguments that can be used in place or to override provided SearchOptions

Returns:

An instance of a SearchResult which provides access to iterate over the search query results and access metadata and metrics about the search query.

Return type:

Deferred[SearchResult]

Raises:

InvalidArgumentException – If a SearchRequest is provided. Use search() for a search request.

txcouchbase.scope.TxScope

alias of Scope