new utility deep_update following rfc7396 plus array edition
[osm/common.git] / osm_common / dbmemory.py
index c27f846..63c93c1 100644 (file)
@@ -33,10 +33,10 @@ class DbMemory(DbBase):
 
     def get_list(self, table, filter={}):
         try:
-            l = []
+            result = []
             for _, row in self._find(table, self._format_filter(filter)):
-                l.append(deepcopy(row))
-            return l
+                result.append(deepcopy(row))
+            return result
         except DbException:
             raise
         except Exception as e:  # TODO refine
@@ -44,17 +44,17 @@ class DbMemory(DbBase):
 
     def get_one(self, table, filter={}, fail_on_empty=True, fail_on_more=True):
         try:
-            l = None
+            result = None
             for _, row in self._find(table, self._format_filter(filter)):
                 if not fail_on_more:
                     return deepcopy(row)
-                if l:
+                if result:
                     raise DbException("Found more than one entry with filter='{}'".format(filter),
                                       HTTPStatus.CONFLICT.value)
-                l = row
-            if not l and fail_on_empty:
+                result = row
+            if not result and fail_on_empty:
                 raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND)
-            return deepcopy(l)
+            return deepcopy(result)
         except Exception as e:  # TODO refine
             raise DbException(str(e))
 
@@ -64,7 +64,7 @@ class DbMemory(DbBase):
             for i, _ in self._find(table, self._format_filter(filter)):
                 id_list.append(i)
             deleted = len(id_list)
-            for i in id_list:
+            for i in reversed(id_list):
                 del self.db[table][i]
             return {"deleted": deleted}
         except DbException:
@@ -94,7 +94,7 @@ class DbMemory(DbBase):
                     raise DbException("Not found entry with filter='{}'".format(filter), HTTPStatus.NOT_FOUND)
                 return None
             self.db[table][i] = deepcopy(indata)
-            return {"upadted": 1}
+            return {"updated": 1}
         except Exception as e:  # TODO refine
             raise DbException(str(e))