deleteByFilterEx method
Deletes data items that match to a given filter.
This method shall be called by a public deleteByFilter method from child class that receives FilterParams and converts them into a filter function.
correlationId
(optional) transaction id to trace execution through call chain.filter
(optional) a filter function to filter items. Return Future that receives null for success. Throws error
Implementation
Future deleteByFilterEx(String? correlationId, Function filter) async {
var deleted = 0;
if (!(filter is Function)) {
throw Exception('Filter parameter must be a function.');
}
for (var index = items.length - 1; index >= 0; index--) {
var item = items[index];
if (filter(item)) {
items.removeAt(index);
deleted++;
}
}
if (deleted == 0) {
return null;
}
logger.trace(correlationId, 'Deleted %s items', [deleted]);
await save(correlationId);
}