def n1ql_index_watch(self, indexes,
                         timeout=30, interval=0.2, watch_primary=False):
        """
        Await completion of index building

        This method will wait up to `timeout` seconds for every index in
        `indexes` to have been built. It will poll the cluster every
        `interval` seconds.

        :param list indexes: A list of indexes to check. This is returned by
            :meth:`build_deferred_indexes`
        :param float timeout: How long to wait for the indexes to become ready.
        :param float interval: How often to poll the cluster.
        :param bool watch_primary: Whether to also watch the primary index.
            This parameter should only be used when manually constructing a
            list of string indexes
        :raise: :exc:`~.TimeoutError` if the timeout was reached before all
            indexes were built
        :raise: :exc:`~.NotFoundError` if one of the indexes passed no longer
            exists.
        """
        kwargs = {
            'timeout_us': int(timeout * 1000000),
            'interval_us': int(interval * 1000000)
        }
        ixlist = [N1qlIndex.from_any(x, self._cb.bucket) for x in indexes]
        if watch_primary:
            ixlist.append(
                N1qlIndex.from_any(N1QL_PRIMARY_INDEX, self._cb.bucket))
        return IxmgmtRequest(self._cb, 'watch', ixlist, **kwargs).execute()
    def _mk_index_def(self, bucket_name, ix, primary=False):
        if isinstance(ix, N1qlIndex):
            return N1qlIndex(ix)

        info = N1qlIndex()
        info.keyspace = bucket_name
        info.primary = primary

        if ix:
            info.name = ix
        elif not primary:
            raise ValueError('Missing name for non-primary index')

        return info
    def get_all_indexes(
            self,  # type: QueryIndexManager
            bucket_name,  # type: str
            *options,  # type: GetAllQueryIndexOptions
            **kwargs  # type: Any
    ):
        # type: (...) -> List[QueryIndex]
        """
        Fetches all indexes from the server.

        :param str bucket_name: the name of the bucket.
        :param GetAllQueryIndexOptions options: Options to use for getting all indexes.
        :param Any kwargs: Override corresponding value in options.
        :return: A list of QueryIndex objects.
        :raises: InvalidArgumentsException
        """
        # N1QL
        # SELECT idx.* FROM system:indexes AS idx
        # WHERE keyspace_id = "bucket_name"
        # ORDER BY is_primary DESC, name ASC
        info = N1qlIndex()
        info.keyspace = bucket_name
        response = IxmgmtRequest(self._admin_bucket, 'list', info,
                                 **forward_args(kwargs, *options)).execute()
        return list(map(QueryIndex.from_n1qlindex, response))
    def n1ql_index_build_deferred(self, other_buckets=False):
        """
        Instruct the server to begin building any previously deferred index
        definitions.

        This method will gather a list of all pending indexes in the cluster
        (including those created using the `defer` option with
        :meth:`create_index`) and start building them in an efficient manner.

        :param bool other_buckets: Whether to also build indexes found in
            other buckets, if possible
        :return: list[couchbase_core._ixmgmt.Index] objects. This
            list contains the indexes which are being built and
            may be passed to :meth:`n1ql_index_watch` to poll
            their build statuses.

        You can use the :meth:`n1ql_index_watch`
        method to wait until all indexes have been built::

            mgr.n1ql_index_create('ix_fld1', fields=['field1'], defer=True)
            mgr.n1ql_index_create('ix_fld2', fields['field2'], defer=True)
            mgr.n1ql_index_create('ix_fld3', fields=['field3'], defer=True)

            indexes = mgr.n1ql_index_build_deferred()
            # [IndexInfo('field1'), IndexInfo('field2'), IndexInfo('field3')]
            mgr.n1ql_index_watch(indexes, timeout=30, interval=1)

        """
        info = N1qlIndex()
        if not other_buckets:
            info.keyspace = self._cb.bucket
            return IxmgmtRequest(self._cb, 'build', info).execute()
    def n1ql_index_list(self, other_buckets=False):
        """
        List indexes in the cluster.

        :param bool other_buckets: Whether to also include indexes belonging
            to other buckets (i.e. buckets other than the current `Bucket`
            object)
        :return: list[couchbase_core._ixmgmt.Index] objects
        """
        info = N1qlIndex()
        if not other_buckets:
            info.keyspace = self._cb.bucket
        return IxmgmtRequest(self._cb, 'list', info).execute()
    def get_all_indexes(
            self,  # type: QueryIndexManager
            bucket_name,  # type: str
            *options,  # type: GetAllQueryIndexOptions
            **kwargs):
        # type: (...)->List[QueryIndex]
        """
        Fetches all indexes from the server.

        :param str bucket_name: the name of the bucket.
        :param Duration timeout: the time allowed for the operation to be terminated. This is controlled by the client.
        :return: A list of QueryIndex objects.


        :raises: InvalidArgumentsException
        """
        # N1QL
        # SELECT idx.* FROM system:indexes AS idx
        # WHERE keyspace_id = "bucket_name"
        # ORDER BY is_primary DESC, name ASC
        info = N1qlIndex()
        info.keyspace = bucket_name
        response = IxmgmtRequest(self._admin_bucket, 'list', info).execute()
        return list(map(QueryIndex.from_n1qlindex, response))
 def _n1ql_index_build_deferred(bucketname, bucket, other_buckets=False):
     info = N1qlIndex()
     if not other_buckets:
         info.keyspace = bucketname
         return IxmgmtRequest(bucket, 'build', info).execute()