Helpers¶
Helper functions for dealing with Cloud Datastore’s Protobuf API.
The non-private functions are part of the API.
- class google.cloud.datastore.helpers.GeoPoint(latitude, longitude)[source]¶
Bases:
object
Simple container for a geo point value.
- __eq__(other)[source]¶
Compare two geo points for equality.
- Return type
- Returns
True if the points compare equal, else False.
- google.cloud.datastore.helpers.entity_from_protobuf(pb)[source]¶
Factory method for creating an entity based on a protobuf.
The protobuf should be one returned from the Cloud Datastore Protobuf API.
- Parameters
pb (
entity_pb2.Entity
) – The Protobuf representing the entity.- Return type
- Returns
The entity derived from the protobuf.
- google.cloud.datastore.helpers.entity_to_protobuf(entity)[source]¶
Converts an entity into a protobuf.
- Parameters
entity (
google.cloud.datastore.entity.Entity
) – The entity to be turned into a protobuf.- Return type
entity_pb2.Entity
- Returns
The protobuf representing the entity.
- google.cloud.datastore.helpers.get_read_options(eventual, transaction_id, read_time=None, new_transaction_options=None)[source]¶
Validate rules for read options, and assign to the request.
Helper method for
lookup()
andrun_query
.- Parameters
eventual (bool) – Flag indicating if
EVENTUAL
orSTRONG
consistency should be used.transaction_id (bytes) – A transaction identifier (may be null).
read_time (datetime) – Read data from the specified time (may be null). This feature is in private preview.
new_transaction_options (
google.cloud.datastore_v1.types.TransactionOptions
) – Options for a new transaction.
- Return type
datastore_pb2.ReadOptions
- Returns
The read options corresponding to the inputs.
- Raises
ValueError
if more than one ofeventual==True
,transaction_id
,read_time
, andnew_transaction_options
is specified.
- google.cloud.datastore.helpers.get_transaction_options(transaction)[source]¶
Get the transaction_id or new_transaction_options field from an active transaction object, for use in get_read_options
These are mutually-exclusive fields, so one or both will be None.
- Return type
Tuple[Optional[bytes], Optional[google.cloud.datastore_v1.types.TransactionOptions]]
- Returns
The transaction_id and new_transaction_options fields from the transaction object.