diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-07-02 16:14:52 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-07-02 18:09:01 +0200 |
| commit | a2a5979bfb392565b55e489b6020aa391e782eb0 (patch) | |
| tree | 00278aaf5f8681a4d26029280fd24a605187839f /opendc-web/opendc-web-api/opendc/database.py | |
| parent | 45b73e4683cce35de79117c5b4a6919556d9644f (diff) | |
api: Add endpoint for simulation jobs
This change adds an API endpoint for simulation jobs which allows API
consumers to manage simulation jobs without needing direct database
access that is currently needed for the web runner.
Diffstat (limited to 'opendc-web/opendc-web-api/opendc/database.py')
| -rw-r--r-- | opendc-web/opendc-web-api/opendc/database.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/opendc-web/opendc-web-api/opendc/database.py b/opendc-web/opendc-web-api/opendc/database.py index 37fd1a4d..dd6367f2 100644 --- a/opendc-web/opendc-web-api/opendc/database.py +++ b/opendc-web/opendc-web-api/opendc/database.py @@ -20,7 +20,7 @@ import urllib.parse -from pymongo import MongoClient +from pymongo import MongoClient, ReturnDocument DATETIME_STRING_FORMAT = '%Y-%m-%dT%H:%M:%S' CONNECTION_POOL = None @@ -76,6 +76,12 @@ class Database: """Updates an existing object.""" return getattr(self.opendc_db, collection).update({'_id': _id}, obj) + def fetch_and_update(self, query, update, collection): + """Updates an existing object.""" + return getattr(self.opendc_db, collection).find_one_and_update(query, + update, + return_document=ReturnDocument.AFTER) + def delete_one(self, query, collection): """Deletes one object matching the given query. |
