Add 'count' to DB utilities

Change-Id: I1a137ceeea21c70cf9358a7bc812ca4e2fe5a240
Signed-off-by: delacruzramo <pedro.delacruzramos@altran.com>
diff --git a/osm_common/dbmemory.py b/osm_common/dbmemory.py
index c994640..d12d03d 100644
--- a/osm_common/dbmemory.py
+++ b/osm_common/dbmemory.py
@@ -161,6 +161,22 @@
         except Exception as e:  # TODO refine
             raise DbException(str(e))
 
+    def count(self, table, q_filter=None):
+        """
+        Count the number of entries matching q_filter
+        :param table: collection or table
+        :param q_filter: Filter
+        :return: number of entries found (can be zero)
+        :raise: DbException on error
+        """
+        try:
+            with self.lock:
+                return sum(1 for x in self._find(table, self._format_filter(q_filter)))
+        except DbException:
+            raise
+        except Exception as e:  # TODO refine
+            raise DbException(str(e))
+
     def get_one(self, table, q_filter=None, fail_on_empty=True, fail_on_more=True):
         """
         Obtain one entry matching q_filter