"""
raise DbException("Method 'get_list' not implemented")
+ 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
+ """
+ raise DbException("Method 'count' not implemented")
+
def get_one(self, table, q_filter=None, fail_on_empty=True, fail_on_more=True):
"""
Obtain one entry matching q_filter
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
except Exception as e: # TODO refine
raise DbException(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:
+ collection = self.db[table]
+ db_filter = self._format_filter(q_filter)
+ count = collection.count(db_filter)
+ return count
+ except DbException:
+ raise
+ except Exception as e: # TODO refine
+ raise DbException(e)
+
def get_one(self, table, q_filter=None, fail_on_empty=True, fail_on_more=True):
"""
Obtain one entry matching q_filter
assert len(db_memory_with_many_data.db) == 1
assert "test" in db_memory_with_many_data.db
assert len(db_memory_with_many_data.db["test"]) == 8
+ result = db_memory_with_many_data.count("test", db_filter)
+ assert result == len(expected_ids)
@pytest.mark.parametrize("table, db_filter, expected_data", [