insertOrUpdateList method

  1. @override
Future<List<TEntity>?> insertOrUpdateList(
  1. Iterable<TEntity> items
)
inherited

Implementation

@override
Future<List<TEntity>?> insertOrUpdateList(Iterable<TEntity> items) async {
  final db = await dbContext.database;
  List<TEntity>? result;
  List<TEntity> updatedItems = <TEntity>[];
  await db.transaction((txn) async {
    var batch = txn.batch();
    for (var element in items) {
      if (element.id == null) {
        element = element.copyWith(id: const Uuid().v4()) as TEntity;
      }
      element = element.updateDates() as TEntity;
      updatedItems.add(element);
      batch.insert(element.meta.tableName, element.toMap(),
          conflictAlgorithm: ConflictAlgorithm.replace);
    }
    result = await _finishBatch(batch, updatedItems);
  });
  return result;
}