adding create_list to dbmongo
[osm/common.git] / osm_common / dbmemory.py
index bfc396d..196d5d9 100644 (file)
@@ -268,6 +268,9 @@ class DbMemory(DbBase):
             k_list = k.split(".")
             k_item_prev = k_list[0]
             populated = False
+            if k_item_prev not in db_nested and populate:
+                populated = True
+                db_nested[k_item_prev] = None
             for k_item in k_list[1:]:
                 if isinstance(db_nested[k_item_prev], dict):
                     if k_item not in db_nested[k_item_prev]:
@@ -369,15 +372,17 @@ class DbMemory(DbBase):
                     raise DbException("Not found entry with _id='{}'".format(q_filter), HTTPStatus.NOT_FOUND)
                 return None
 
-    def set_list(self, table, q_filter, update_dict, fail_on_empty=True, unset=None, pull=None, push=None):
+    def set_list(self, table, q_filter, update_dict, unset=None, pull=None, push=None):
         with self.lock:
             updated = 0
-            for i, db_item in self._find(table, self._format_filter(q_filter)):
+            found = 0
+            for _, db_item in self._find(table, self._format_filter(q_filter)):
+                found += 1
                 if self._update(db_item, update_dict, unset=unset, pull=pull, push=push):
                     updated += 1
-            if i == 0 and fail_on_empty:
-                raise DbException("Not found entry with _id='{}'".format(q_filter), HTTPStatus.NOT_FOUND)
-            return {"updated": updated} if i else None
+            # if not found and fail_on_empty:
+            #     raise DbException("Not found entry with '{}'".format(q_filter), HTTPStatus.NOT_FOUND)
+            return {"updated": updated} if found else None
 
     def replace(self, table, _id, indata, fail_on_empty=True):
         """
@@ -409,7 +414,7 @@ class DbMemory(DbBase):
         Add a new entry at database
         :param table: collection or table
         :param indata: content to be added
-        :return: database id of the inserted element. Raises a DbException on error
+        :return: database '_id' of the inserted element. Raises a DbException on error
         """
         try:
             id = indata.get("_id")
@@ -429,7 +434,7 @@ class DbMemory(DbBase):
         Add a new entry at database
         :param table: collection or table
         :param indata_list: list content to be added
-        :return: database ids of the inserted element. Raises a DbException on error
+        :return: list of inserted 'id's. Raises a DbException on error
         """
         try:
             _ids = []