From 9b08dc68b272b7c84feff5ea4b9124fb5684aa6d Mon Sep 17 00:00:00 2001 From: Keiran Price Date: Thu, 20 Jun 2019 07:36:23 +0100 Subject: [PATCH] #1: Add patch function --- common/database_helpers.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/database_helpers.py b/common/database_helpers.py index 9b7fa768..e9d22653 100644 --- a/common/database_helpers.py +++ b/common/database_helpers.py @@ -173,3 +173,21 @@ def get_first_filtered_row(table, filters): :return: the first row matching the filter """ return get_rows_by_filter(table, filters)[0] + + +def patch_entities(table, json_list): + """ + Update one or more rows in the given table, from the given list containing json. Each entity must contain its ID + :param table: The table of the entities + :param json_list: the list of updated values + :return: The list of updated rows. + """ + results = [] + for entity in json_list: + for key in entity: + if key.upper() == "ID": + update_row_from_id(table, entity[key], entity) + result = get_row_by_id(table, entity[key]) + results.append(result) + + return results