Skip to content

Commit

Permalink
Add delete_doc
Browse files Browse the repository at this point in the history
  • Loading branch information
as2388 committed Nov 1, 2021
1 parent 009212b commit 1a9a2da
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions engagement_database/engagement_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,26 @@ def restore_doc(self, doc, path, transaction=None):
else:
transaction.set(ref, doc.to_dict())

def delete_doc(self, path, transaction=None):
"""
Deletes a doc from the database.
CAUTION: If used without care, this can break history. To archive messages while correctly preserving history,
use `set_message` instead.
:param path: Path to the document to delete, relative to the the engagement database root document.
:type path: str
:param transaction: Transaction to run this update in or None.
If None, writes immediately, otherwise adds the updates to a transaction that will need
to be explicitly committed elsewhere.
:type transaction: google.cloud.firestore.Transaction | None
"""
ref = self._client.document(f"{self._database_path}/{path}")
if transaction is None:
ref.delete()
else:
transaction.delete(ref)

def restore_history_entry(self, history_entry, transaction=None):
"""
Restores a history entry to the database.
Expand Down

0 comments on commit 1a9a2da

Please sign in to comment.