diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-06-23 18:10:05 +0200 |
|---|---|---|
| committer | Georgios Andreadis <info@gandreadis.com> | 2020-06-23 18:10:05 +0200 |
| commit | c14ff547d4f6b6569bab3293ee574b03a8770ae3 (patch) | |
| tree | ded4f1160410923a400ade8517c2c728c503830a /opendc/util | |
| parent | 565ede0dc50c3b2df09c066ea3a28a4901cce547 (diff) | |
Add deletion methods
Diffstat (limited to 'opendc/util')
| -rw-r--r-- | opendc/util/database.py | 20 |
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) |
