chunkById method

  1. @override
Future<void> chunkById(
  1. int chunk,
  2. void callback(
    1. List<Map<String, dynamic>> data
    ), [
  3. String column = 'id'
])
inherited

Implementation

@override
Future<void> chunkById(
  int chunk,
  void Function(List<Map<String, dynamic>> data) callback, [
  String column = 'id',
]) async {
  try {
    int lastId = 0;

    while (true) {
      whereGreaterThan(column, lastId).orderByAsc(column).limit(chunk);
      final result = await get();
      if (result.isEmpty) {
        break;
      }
      callback(result);
      lastId = int.parse(result.last[column].toString());

      if (result.length < chunk) {
        break;
      }
    }
  } catch (e) {
    rethrow;
  }
}