findPaginatedByQuery method
Retrieves a page of entities from the database that match the given query
sorted by the given sort
. skip
and limit
are used to determine the
offset and size of the page.
Returns a Future that completes with a Page
of entities.
Implementation
@override
Future<Page<T>> findPaginatedByQuery(Query query, Sorted sort,
{required int skip, required int limit}) {
var comparator = MapSorting.parse(sort.sort);
var totalElements = 0;
var values = _data.entries
.where((element) =>
MapMatcher.evaluate(query.filter, element.value, system))
.sorted((a, b) => comparator.compare(a.value, b.value))
.map((e) {
totalElements++;
return e;
})
.toList() // Get all so the totalElements can be calculated
.skip(skip)
.take(limit)
.map((e) => EntityIntermediate(e.key, e.value))
.map((e) => analysis.decode(e))
.toList();
var page = Page<T>.fromData(values, skip, limit, totalElements);
return Future.value(page);
}