def modify_write(self, write_pb, no_create_msg=None): """Modify a ``Write`` protobuf based on the state of this write option. If: * ``create_if_missing=False``, adds a precondition that requires existence * ``create_if_missing=True``, does not add any precondition * ``no_create_msg`` is passed, raises an exception. For example, in a :meth:`~.DocumentReference.delete`, no "create" can occur, so it wouldn't make sense to "create if missing". Args: write_pb (google.cloud.firestore_v1beta1.types.Write): A ``Write`` protobuf instance to be modified with a precondition determined by the state of this option. no_create_msg (Optional[str]): A message to use to indicate that a create operation is not allowed. Raises: ValueError: If ``no_create_msg`` is passed. """ if no_create_msg is not None: raise ValueError(no_create_msg) elif not self._create_if_missing: current_doc = types.Precondition(exists=True) write_pb.current_document.CopyFrom(current_doc)
def modify_write(self, write_pb, **unused_kwargs): """Modify a ``Write`` protobuf based on the state of this write option. The ``last_update_time`` is added to ``write_pb`` as an "update time" precondition. When set, the target document must exist and have been last updated at that time. Args: write_pb (google.cloud.firestore_v1beta1.types.Write): A ``Write`` protobuf instance to be modified with a precondition determined by the state of this option. unused_kwargs (Dict[str, Any]): Keyword arguments accepted by other subclasses that are unused here. """ current_doc = types.Precondition(update_time=self._last_update_time) write_pb.current_document.CopyFrom(current_doc)
def modify_write(self, write_pb, **unused_kwargs): """Modify a ``Write`` protobuf based on the state of this write option. If: * ``exists=True``, adds a precondition that requires existence * ``exists=False``, adds a precondition that requires non-existence Args: write_pb (google.cloud.firestore_v1beta1.types.Write): A ``Write`` protobuf instance to be modified with a precondition determined by the state of this option. unused_kwargs (Dict[str, Any]): Keyword arguments accepted by other subclasses that are unused here. """ current_doc = types.Precondition(exists=self._exists) write_pb.current_document.CopyFrom(current_doc)