Пример #1
0
    def delete(self, option=None):
        """Delete the current document in the Firestore database.

        Args:
            option (Optional[~.firestore_v1beta1.client.WriteOption]): A
               write option to make assertions / preconditions on the server
               state of the document before applying changes. Note that
               ``create_if_missing`` can't be used here since it does not
               apply (i.e. a "delete" cannot "create").

        Returns:
            google.protobuf.timestamp_pb2.Timestamp: The time that the delete
            request was received by the server. If the document did not exist
            when the delete was sent (i.e. nothing was deleted), this method
            will still succeed and will still return the time that the
            request was received by the server.

        Raises:
            ValueError: If the ``create_if_missing`` write option is used.
        """
        write_pb = _helpers.pb_for_delete(self._document_path, option)
        with _helpers.remap_gax_error_on_commit():
            commit_response = self._client._firestore_api.commit(
                self._client._database_string, [write_pb],
                transaction=None,
                options=self._client._call_options)

        return commit_response.commit_time
Пример #2
0
    def commit(self):
        """Commit the changes accumulated in this batch.

        Returns:
            List[google.cloud.proto.firestore.v1beta1.\
                write_pb2.WriteResult, ...]: The write results corresponding
            to the changes committed, returned in the same order as the
            changes were applied to this batch. A write result contains an
            ``update_time`` field.
        """
        with _helpers.remap_gax_error_on_commit():
            commit_response = self._client._firestore_api.commit(
                self._client._database_string, self._write_pbs,
                transaction=None, options=self._client._call_options)

        self._write_pbs = []
        return list(commit_response.write_results)
    def _commit(self):
        """Transactionally commit the changes accumulated.

        Returns:
            List[google.cloud.proto.firestore.v1beta1.\
                write_pb2.WriteResult, ...]: The write results corresponding
            to the changes committed, returned in the same order as the
            changes were applied to this transaction. A write result contains
            an ``update_time`` field.

        Raises:
            ValueError: If no transaction is in progress.
        """
        if not self.in_progress:
            raise ValueError(_CANT_COMMIT)

        with _helpers.remap_gax_error_on_commit():
            commit_response = _commit_with_retry(self._client, self._write_pbs,
                                                 self._id)

        self._clean_up()
        return list(commit_response.write_results)