batchProcess method

  1. @override
Future<void> batchProcess({
  1. required int batchSize,
  2. required Future<void> processor(
    1. List<Map<String, dynamic>> batch,
    2. int batchNumber
    ),
  3. List<String> columns = const ['*'],
})
inherited

Implementation

@override
Future<void> batchProcess({
  required int batchSize,
  required Future<void> Function(
          List<Map<String, dynamic>> batch, int batchNumber)
      processor,
  List<String> columns = const ['*'],
}) async {
  int batchNumber = 1;
  int offset = 0;

  while (true) {
    final batchQuery = QueryBuilderImpl()
      ..table(getTable)
      ..select(columns)
      ..limit(batchSize)
      ..offset(offset);

    final batch = await batchQuery.get();

    if (batch.isEmpty) break;

    await processor(batch, batchNumber);

    if (batch.length < batchSize) break;

    offset += batchSize;
    batchNumber++;
  }
}