summaryrefslogtreecommitdiff
path: root/jimbrella/database.py
diff options
context:
space:
mode:
Diffstat (limited to 'jimbrella/database.py')
-rw-r--r--jimbrella/database.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/jimbrella/database.py b/jimbrella/database.py
index a8d480b..9b6e51f 100644
--- a/jimbrella/database.py
+++ b/jimbrella/database.py
@@ -91,7 +91,7 @@ class Database(CsvTable):
umbrellas[idx]["lent_time_ago_str"] = human_timedelta(lent_time_ago)
return umbrellas
- def update(self, umb) -> list:
+ def update(self, umb) -> dict:
"""An interface to `_update()` with added convenience and safeguards.
Convenience: Not all fields in an umbrella dict need to be present in `umb`. If an
@@ -117,7 +117,8 @@ class Database(CsvTable):
fields mentioned above are made blank, and these fields supplied in `umb`
are ignored.
- Returns updated database (same as `_update()`).
+ Returns a dict, where the keys are all modified columns of the updated row, and the value
+ of each is a 2-tuple (<past value>, <new value>).
"""
# `serial` must be specified.
if "serial" not in umb:
@@ -169,7 +170,19 @@ class Database(CsvTable):
if not umb["lent_at"]:
raise UmbrellaValueError("lent_at")
- return self._update(umb)
+ # commit update
+ self._update(umb)
+
+ # find updated columns
+ # essentially "diff umb_in_db umb"
+ diff = {}
+ for key, new in umb.items():
+ past = umb_in_db[key]
+ if any([new, past]) and new != past:
+ # new and past are not both null values, and they are unequal
+ diff[key] = (past, new)
+
+ return diff
@staticmethod
def group_by_status(umbrellas) -> dict: