paginate method
Returns a paginated result.
Implementation
Future<PaginatedResult<T>> paginate({int page = 1, int perPage = 15}) async {
final total = await ModelQuery<T>(_executor, _factory, tableName: _tableName)
.count();
final items = await ModelQuery<T>(_executor, _factory, tableName: _tableName)
.limit(perPage)
.offset((page - 1) * perPage)
.orderBy('id')
.get();
return PaginatedResult<T>(
items: items,
total: total,
page: page,
perPage: perPage,
lastPage: (total / perPage).ceil(),
);
}