Exemplo n.º 1
0
    async def get_all(
        self,
        references: list,
        field_paths: Iterable[str] = None,
        transaction=None,
    ) -> AsyncGenerator[DocumentSnapshot, Any]:
        """Retrieve a batch of documents.

        .. note::

           Documents returned by this method are not guaranteed to be
           returned in the same order that they are given in ``references``.

        .. note::

           If multiple ``references`` refer to the same document, the server
           will only return one result.

        See :meth:`~google.cloud.firestore_v1.client.Client.field_path` for
        more information on **field paths**.

        If a ``transaction`` is used and it already has write operations
        added, this method cannot be used (i.e. read-after-write is not
        allowed).

        Args:
            references (List[.AsyncDocumentReference, ...]): Iterable of document
                references to be retrieved.
            field_paths (Optional[Iterable[str, ...]]): An iterable of field
                paths (``.``-delimited list of field names) to use as a
                projection of document fields in the returned results. If
                no value is provided, all fields will be returned.
            transaction (Optional[:class:`~google.cloud.firestore_v1.async_transaction.AsyncTransaction`]):
                An existing transaction that these ``references`` will be
                retrieved in.

        Yields:
            .DocumentSnapshot: The next document snapshot that fulfills the
            query, or :data:`None` if the document does not exist.
        """
        document_paths, reference_map = _reference_info(references)
        mask = _get_doc_mask(field_paths)
        response_iterator = await self._firestore_api.batch_get_documents(
            request={
                "database": self._database_string,
                "documents": document_paths,
                "mask": mask,
                "transaction": _helpers.get_transaction_id(transaction),
            },
            metadata=self._rpc_metadata,
        )

        async for get_doc_response in response_iterator:
            yield _parse_batch_get(get_doc_response, reference_map, self)
Exemplo n.º 2
0
def test__reference_info():
    from google.cloud.firestore_v1.base_client import _reference_info

    expected_doc_paths = ["/a/b", "/a/b/c/d", "/a/b", "/f/g"]
    documents = [mock.Mock(_document_path=path) for path in expected_doc_paths]

    document_paths, reference_map = _reference_info(documents)

    assert document_paths == expected_doc_paths
    # reference3 over-rides reference1.
    expected_map = {
        path: document
        for path, document in list(zip(expected_doc_paths, documents))[1:]
    }
    assert reference_map == expected_map
Exemplo n.º 3
0
    def _call_fut(references):
        from google.cloud.firestore_v1.base_client import _reference_info

        return _reference_info(references)