bulkDeleteWhere method

  1. @override
Future<bool> bulkDeleteWhere(
  1. List<Map<String, dynamic>> conditions, {
  2. int batchSize = 500,
})
inherited

Implementation

@override
Future<bool> bulkDeleteWhere(
  List<Map<String, dynamic>> conditions, {
  int batchSize = 500,
}) async {
  if (conditions.isEmpty) {
    throw InvalidArgumentException(
        'Conditions cannot be empty for bulk delete operation');
  }

  try {
    final conn = await getConnection();
    for (int i = 0; i < conditions.length; i += batchSize) {
      final batch = conditions.skip(i).take(batchSize).toList();
      final paramBindings = <String, dynamic>{};

      final orConditions = <String>[];

      for (var conditionMap in batch) {
        final andConditions = <String>[];

        for (var entry in conditionMap.entries) {
          final paramName = _nextParamName();
          paramBindings[paramName] = entry.value;
          andConditions.add("${entry.key} = :$paramName");
        }

        orConditions.add("(${andConditions.join(' AND ')})");
      }

      final sql = "DELETE FROM $getTable WHERE ${orConditions.join(' OR ')}";

      await conn.execute(sql, paramBindings);
    }

    return true;
  } catch (e) {
    rethrow;
  }
}