| 38 | |
| 39 | |
| 40 | class Scope: |
| 41 | |
| 42 | def __init__(self, bucket: Bucket, scope_name: str) -> None: |
| 43 | self._impl = ScopeImpl(scope_name, bucket) |
| 44 | |
| 45 | @property |
| 46 | def name(self) -> str: |
| 47 | """ |
| 48 | str: The name of this :class:`~.Scope` instance. |
| 49 | """ |
| 50 | return self._impl.name |
| 51 | |
| 52 | @property |
| 53 | def bucket_name(self) -> str: |
| 54 | """ |
| 55 | str: The name of the bucket in which this :class:`~.Scope` instance belongs. |
| 56 | """ |
| 57 | return self._impl.bucket_name |
| 58 | |
| 59 | def collection(self, name: str) -> Collection: |
| 60 | """Creates a :class:`~.collection.Collection` instance of the specified collection. |
| 61 | |
| 62 | Args: |
| 63 | name (str): Name of the collection to reference. |
| 64 | |
| 65 | Returns: |
| 66 | :class:`~.collection.Collection`: A :class:`~.collection.Collection` instance of the specified collection. |
| 67 | """ |
| 68 | return Collection(self, name) |
| 69 | |
| 70 | def query(self, |
| 71 | statement, # type: str |
| 72 | *options, # type: QueryOptions |
| 73 | **kwargs # type: Dict[str, Any] |
| 74 | ) -> QueryResult: |
| 75 | """Executes a N1QL query against the scope. |
| 76 | |
| 77 | .. note:: |
| 78 | The query is executed lazily in that it is executed once iteration over the |
| 79 | :class:`~couchbase.result.QueryResult` begins. |
| 80 | |
| 81 | .. note:: |
| 82 | Scope-level queries are only supported on Couchbase Server versions that support scopes and collections. |
| 83 | |
| 84 | .. seealso:: |
| 85 | * :class:`~couchbase.management.queries.QueryIndexManager`: For how to manage query indexes. |
| 86 | * :meth:`~couchbase.cluster.Cluster.query`: For how to execute cluster-level queries. |
| 87 | |
| 88 | Args: |
| 89 | statement (str): The N1QL statement to execute. |
| 90 | options (:class:`~couchbase.options.QueryOptions`): Optional parameters for the query operation. |
| 91 | **kwargs (Dict[str, Any]): keyword arguments that can be used in place or to |
| 92 | override provided :class:`~couchbase.options.QueryOptions` |
| 93 | |
| 94 | Returns: |
| 95 | :class:`~couchbase.result.QueryResult`: An instance of a :class:`~couchbase.result.QueryResult` which |
| 96 | provides access to iterate over the query results and access metadata and metrics about the query. |
| 97 | |