def to_delete_mutation(key): if not helper.is_key_valid(key): raise ValueError('Keys to be deleted from the Cloud Datastore must be ' 'complete:\n%s', key) mutation = datastore_pb2.Mutation() mutation.delete.CopyFrom(key) return mutation
def to_upsert_mutation(entity): if not helper.is_key_valid(entity.key): raise ValueError('Entities to be written to the Cloud Datastore must ' 'have complete keys:\n%s' % entity) mutation = datastore_pb2.Mutation() mutation.upsert.CopyFrom(entity) return mutation
def _add_delete_key_pb(self): """Adds a new mutation for a key to be deleted. :rtype: :class:`.entity_pb2.Key` :returns: The newly created key protobuf that will be deleted when sent with a commit. """ new_mutation = _datastore_pb2.Mutation() self._mutations.append(new_mutation) return new_mutation.delete
def _add_partial_key_entity_pb(self): """Adds a new mutation for an entity with a partial key. :rtype: :class:`.entity_pb2.Entity` :returns: The newly created entity protobuf that will be updated and sent with a commit. """ new_mutation = _datastore_pb2.Mutation() self._mutations.append(new_mutation) return new_mutation.insert
def _add_complete_key_entity_pb(self): """Adds a new mutation for an entity with a completed key. :rtype: :class:`.entity_pb2.Entity` :returns: The newly created entity protobuf that will be updated and sent with a commit. """ # We use ``upsert`` for entities with completed keys, rather than # ``insert`` or ``update``, in order not to create race conditions # based on prior existence / removal of the entity. new_mutation = _datastore_pb2.Mutation() self._mutations.append(new_mutation) return new_mutation.upsert