summaryrefslogtreecommitdiff
path: root/opendc/util/database.py
diff options
context:
space:
mode:
authorGeorgios Andreadis <info@gandreadis.com>2020-06-23 18:10:05 +0200
committerGeorgios Andreadis <info@gandreadis.com>2020-06-23 18:10:05 +0200
commitc14ff547d4f6b6569bab3293ee574b03a8770ae3 (patch)
treeded4f1160410923a400ade8517c2c728c503830a /opendc/util/database.py
parent565ede0dc50c3b2df09c066ea3a28a4901cce547 (diff)
Add deletion methods
Diffstat (limited to 'opendc/util/database.py')
-rw-r--r--opendc/util/database.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/opendc/util/database.py b/opendc/util/database.py
index 67632bd0..0e424aa4 100644
--- a/opendc/util/database.py
+++ b/opendc/util/database.py
@@ -58,6 +58,26 @@ def update(_id, obj, collection):
return convert_bson_to_json(bson)
+def delete_one(query, collection):
+ """Deletes one object matching the given query.
+
+ The query needs to be in json format, i.e.: `{'name': prefab_name}`.
+ """
+ bson = getattr(opendcdb, collection).delete_one(query)
+
+ return convert_bson_to_json(bson)
+
+
+def delete_all(query, collection):
+ """Deletes all objects matching the given query.
+
+ The query needs to be in json format, i.e.: `{'name': prefab_name}`.
+ """
+ bson = getattr(opendcdb, collection).delete_many(query)
+
+ return convert_bson_to_json(bson)
+
+
def convert_bson_to_json(bson):
# Convert BSON representation to JSON
json_string = dumps(bson)