all method
Deletes all documents of a specific type from RDB.
Implementation
@override
Future<void> all(Type type, { required bool iAmSure, String? subcollection }) async {
if (iAmSure) {
final String? className = RDB.classNames[type];
if (className == null) {
throw UnsupportedError('No class name found for type: $type. Consider re-generating Firestorm data classes.');
}
//Get the objects of this type:
final reference = RDB.instance.ref(className);
final snapshot = await reference.once();
if (snapshot.snapshot.value == null) {
return;
}
Map<String, dynamic> data = RDBDeserializationHelper.snapshotToMap(snapshot.snapshot);
final Map<String, dynamic> updates = {};
data.forEach((key, value) {
String path = key.toString();
updates[path] = null; // Mark for deletion
});
// Perform the deletion in a single update operation:
return await reference.update(updates);
}
}