insertCollection method

Future<void> insertCollection(
  1. List<T> entries
)

Insert a collection of entries to this table.

Implementation

Future<void> insertCollection(List<T> entries) async {
  if (entries.isEmpty) return;
  try {
    var db = await _initializeDB();
    var batch = db.batch();
    for (var entry in entries) {
      await entry.beforeSave(true);
      var map = <String, dynamic>{};
      entry.creationTime.value = DateTime.now();
      entry.modificationTime.value = DateTime.now();
      _setEntryToMap(entry, map);
      batch.insert(tableName, map);
      await entry.afterSave(true);
    }
    var result = await batch.commit();
    for (int i = 0; i < entries.length; i++) {
      entries[i].id.value = result[i] as int?;
      _fireChangeListners(EntryChangeType.Insertion, entries[i]);
    }
  } catch (e) {
    return;
  }
}