diff --git a/google/cloud/firestore_v1/async_client.py b/google/cloud/firestore_v1/async_client.py index 4dd17035c..00029074b 100644 --- a/google/cloud/firestore_v1/async_client.py +++ b/google/cloud/firestore_v1/async_client.py @@ -40,6 +40,12 @@ from google.cloud.firestore_v1.async_collection import AsyncCollectionReference from google.cloud.firestore_v1.async_document import AsyncDocumentReference from google.cloud.firestore_v1.async_transaction import AsyncTransaction +from google.cloud.firestore_v1.services.firestore import ( + async_client as firestore_client, +) +from google.cloud.firestore_v1.services.firestore.transports import ( + grpc_asyncio as firestore_grpc_transport, +) class AsyncClient(BaseClient): @@ -86,6 +92,29 @@ def __init__( client_options=client_options, ) + @property + def _firestore_api(self): + """Lazy-loading getter GAPIC Firestore API. + Returns: + :class:`~google.cloud.gapic.firestore.v1`.async_firestore_client.FirestoreAsyncClient: + The GAPIC client with the credentials of the current client. + """ + return self._firestore_api_helper( + firestore_grpc_transport.FirestoreGrpcAsyncIOTransport, + firestore_client.FirestoreAsyncClient, + firestore_client, + ) + + @property + def _target(self): + """Return the target (where the API is). + Eg. "firestore.googleapis.com" + + Returns: + str: The location of the API. + """ + return self._target_helper(firestore_client.FirestoreAsyncClient) + def collection(self, *collection_path): """Get a reference to a collection. @@ -233,7 +262,7 @@ async def collections(self): Sequence[:class:`~google.cloud.firestore_v1.async_collection.AsyncCollectionReference`]: iterator of subcollections of the current document. """ - iterator = self._firestore_api.list_collection_ids( + iterator = await self._firestore_api.list_collection_ids( request={"parent": "{}/documents".format(self._database_string)}, metadata=self._rpc_metadata, ) @@ -242,7 +271,7 @@ async def collections(self): for i in iterator.collection_ids: yield self.collection(i) if iterator.next_page_token: - iterator = self._firestore_api.list_collection_ids( + iterator = await self._firestore_api.list_collection_ids( request={ "parent": "{}/documents".format(self._database_string), "page_token": iterator.next_page_token, diff --git a/google/cloud/firestore_v1/base_client.py b/google/cloud/firestore_v1/base_client.py index 288a55d56..538cafefa 100644 --- a/google/cloud/firestore_v1/base_client.py +++ b/google/cloud/firestore_v1/base_client.py @@ -35,10 +35,6 @@ from google.cloud.firestore_v1 import types from google.cloud.firestore_v1.base_document import DocumentSnapshot from google.cloud.firestore_v1.field_path import render_field_path -from google.cloud.firestore_v1.services.firestore import client as firestore_client -from google.cloud.firestore_v1.services.firestore.transports import ( - grpc as firestore_grpc_transport, -) DEFAULT_DATABASE = "(default)" """str: The default database used in a :class:`~google.cloud.firestore_v1.client.Client`.""" @@ -117,12 +113,10 @@ def __init__( self._database = database self._emulator_host = os.getenv(_FIRESTORE_EMULATOR_HOST) - @property - def _firestore_api(self): + def _firestore_api_helper(self, transport, client_class, client_module): """Lazy-loading getter GAPIC Firestore API. Returns: - :class:`~google.cloud.gapic.firestore.v1`.firestore_client.FirestoreClient: -