many<T> method
Creates multiple documents in Localstore from a list of objects. Uses a batch operation for efficiency.
Implementation
@override
Future<void> many<T>(List<T> objects, { String? subcollection }) async {
if (objects.length > 500) {
throw ArgumentError('Batch limit exceeded. Maximum 500 objects allowed.');
}
if (objects.isEmpty) {
return Future.value();
}
final serializer = LS.serializers[objects[0].runtimeType];
if (serializer == null) {
throw UnsupportedError('No serializer found for type: ${objects[0].runtimeType}. Consider re-generating Firestorm data classes.');
}
List<Future> futures = [];
for (var object in objects) {
final map = serializer(object);
if (map["id"].isEmpty) {
throw NullIDException(map);
}
DocumentRef documentReference = LS.instance.collection(T.toString()).doc(map["id"]);
if (subcollection != null) {
documentReference = LS.instance.collection(T.toString()).doc(subcollection).collection(subcollection).doc(map["id"]);
}
futures.add(documentReference.set(serializer(object)));
}
await Future.wait(futures);
}