X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_common%2Fdbmemory.py;fp=osm_common%2Fdbmemory.py;h=d12d03ddc3a20ce52e3a18d907ddb920c0edde2f;hb=ae049d8467e5ce1b1be8487ed93031b594dc0230;hp=c994640d77d78c082aedd7bfcf14d7c40b266da5;hpb=6472e2b6e90c263b59c1195a952fbf4b7d35eba0;p=osm%2Fcommon.git 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 @@ class DbMemory(DbBase): 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