Skip to content

Commit 1547a9f

Browse files
committed
Add docstrings for the new methods.
1 parent 42c2b28 commit 1547a9f

2 files changed

Lines changed: 128 additions & 3 deletions

File tree

datastore/google/cloud/datastore/client.py

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,40 @@ def get(self, key, missing=None, deferred=None, transaction=None, eventual=False
368368
return None
369369

370370
def get_entity_pb(self, key, missing=None, deferred=None, transaction=None, eventual=False):
371-
"""Retrieve a single raw Entity Protobuf object from a datastore.
371+
"""Retrieve a single Entity Protobuf object for the provided key.
372+
373+
.. note::
374+
375+
This method is the same as "get()" method, but it works with raw Entity Protobuf
376+
object (:class:`.entity_pb2.Entity`) instead of Entity Python class
377+
(:class:`google.cloud.datastore.entity.Entity`).
378+
379+
:type key: :class:`google.cloud.datastore.key.Key`
380+
:param key: The key to be retrieved from the datastore.
381+
382+
:type missing: list
383+
:param missing: (Optional) If a list is passed, the key-only entities
384+
returned by the backend as "missing" will be copied
385+
into it.
386+
387+
:type deferred: list
388+
:param deferred: (Optional) If a list is passed, the keys returned
389+
by the backend as "deferred" will be copied into it.
390+
391+
:type transaction:
392+
:class:`~google.cloud.datastore.transaction.Transaction`
393+
:param transaction: (Optional) Transaction to use for read consistency.
394+
If not passed, uses current transaction, if set.
395+
396+
:type eventual: bool
397+
:param eventual: (Optional) Defaults to strongly consistent (False).
398+
Setting True will use eventual consistency, but cannot
399+
be used inside a transaction or will raise ValueError.
400+
401+
:rtype: :class:`.entity_pb2.Entity` or ``NoneType``
402+
:returns: The requested entity protobuf object if it exists.
403+
404+
:raises: :class:`ValueError` if eventual is True and in a transaction.
372405
"""
373406
entity_pbs = self.get_multi_entity_pb(
374407
keys=[key],
@@ -425,6 +458,44 @@ def get_multi(
425458
def get_multi_entity_pb(
426459
self, keys, missing=None, deferred=None, transaction=None, eventual=False
427460
):
461+
"""Retrieve raw Entity protobuf objects for the provided keys.
462+
463+
.. note::
464+
465+
This method is the same as "get_multi()" method, but it works with raw Entity
466+
Protobuf object (:class:`.entity_pb2.Entity`) instead of Entity Python class
467+
(:class:`google.cloud.datastore.entity.Entity`).
468+
469+
:type keys: list of :class:`google.cloud.datastore.key.Key`
470+
:param keys: The keys to be retrieved from the datastore.
471+
472+
:type missing: list
473+
:param missing: (Optional) If a list is passed, the key-only entities
474+
returned by the backend as "missing" will be copied
475+
into it. If the list is not empty, an error will occur.
476+
477+
:type deferred: list
478+
:param deferred: (Optional) If a list is passed, the keys returned
479+
by the backend as "deferred" will be copied into it.
480+
If the list is not empty, an error will occur.
481+
482+
:type transaction:
483+
:class:`~google.cloud.datastore.transaction.Transaction`
484+
:param transaction: (Optional) Transaction to use for read consistency.
485+
If not passed, uses current transaction, if set.
486+
487+
:type eventual: bool
488+
:param eventual: (Optional) Defaults to strongly consistent (False).
489+
Setting True will use eventual consistency, but cannot
490+
be used inside a transaction or will raise ValueError.
491+
492+
:rtype: list of:class:`.entity_pb2.Entity`
493+
:returns: The requested entities (protobuf objects).
494+
495+
:raises: :class:`ValueError` if one or more of ``keys`` has a project
496+
which does not match our project.
497+
:raises: :class:`ValueError` if eventual is True and in a transaction.
498+
"""
428499
return self._get_multi(keys=keys, missing=missing, deferred=deferred,
429500
transaction=transaction, eventual=eventual)
430501

@@ -445,6 +516,15 @@ def put(self, entity):
445516
def put_entity_pb(self, entity_pb):
446517
"""
447518
Save a single raw Entity Protobuf object in the Cloud Datastore.
519+
520+
.. note::
521+
522+
This method is the same as "put()" method, but it works with raw Entity Protobuf
523+
object (:class:`.entity_pb2.Entity`) instead of Entity Python class
524+
(:class:`google.cloud.datastore.entity.Entity`).
525+
526+
:type entity_pb: :class:`.entity_pb2.Entity`
527+
:param entity_pb: The entity to be saved to the datastore.
448528
"""
449529
self.put_multi_entity_pbs(entity_pbs=[entity_pb])
450530

@@ -478,6 +558,17 @@ def put_multi(self, entities):
478558
def put_multi_entity_pbs(self, entity_pbs):
479559
"""
480560
Save multiple raw Entity Protobuf objects in the Cloud Datastore.
561+
562+
.. note::
563+
564+
This method is the same as "put_multi()" method, but it works with raw Entity Protobuf
565+
object (:class:`.entity_pb2.Entity`) instead of Entity Python class
566+
(:class:`google.cloud.datastore.entity.Entity`).
567+
568+
:type entity_pbs: list of :class:`.entity_pb2.Entity`
569+
:param entity_pbs: The entities to be saved to the datastore.
570+
571+
:raises: :class:`ValueError` if ``entities`` is a single entity.
481572
"""
482573
if not entity_pbs:
483574
return

datastore/google/cloud/datastore/query.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,38 @@ def fetch_entity_pb(
401401
client=None,
402402
eventual=False,
403403
):
404-
"""Execute the query, return iterator for the matching raw Entity
405-
Protobuf objects.
404+
"""Execute the query, return iterator for the matching raw Entity Protobuf objects.
405+
406+
.. note::
407+
408+
This method is the same as "fetch()" method, but it works with raw Entity Protobuf
409+
objects (:class:`.entity_pb2.Entity`) instead of Entity Python class
410+
(:class:`google.cloud.datastore.entity.Entity`).
411+
412+
:type limit: int
413+
:param limit: (Optional) limit passed through to the iterator.
414+
415+
:type offset: int
416+
:param offset: (Optional) offset passed through to the iterator.
417+
418+
:type start_cursor: bytes
419+
:param start_cursor: (Optional) cursor passed through to the iterator.
420+
421+
:type end_cursor: bytes
422+
:param end_cursor: (Optional) cursor passed through to the iterator.
423+
424+
:type client: :class:`google.cloud.datastore.client.Client`
425+
:param client: (Optional) client used to connect to datastore.
426+
If not supplied, uses the query's value.
427+
428+
:type eventual: bool
429+
:param eventual: (Optional) Defaults to strongly consistent (False).
430+
Setting True will use eventual consistency,
431+
but cannot be used inside a transaction or
432+
will raise ValueError.
433+
434+
:rtype: :class:`Iterator` of :class:`.entity_pb2.Entity`
435+
:returns: The iterator for the query.
406436
"""
407437
if client is None:
408438
client = self._client
@@ -449,6 +479,10 @@ class Iterator(page_iterator.Iterator):
449479
Setting True will use eventual consistency,
450480
but cannot be used inside a transaction or
451481
will raise ValueError.
482+
483+
:type item_to_value: callable
484+
:param item_to_value: (Optional) Conversion function which will be called
485+
for each iterator item.
452486
"""
453487

454488
next_page_token = None

0 commit comments

Comments
 (0)