Add bulk replace

This commit is contained in:
Moshe Dicker 2024-04-17 13:54:26 -04:00
parent ae41baaf7b
commit 1a68efce58
1 changed files with 12 additions and 0 deletions

View File

@ -564,4 +564,16 @@ abstract class RootTableManager<
Future<bool> replace(Insertable<D> entity) {
return $state.db.update($state._tableAsTableInfo).replace(entity);
}
/// Replace multiple rows in the table
///
/// If any of the [entities] has an absent value (set to null on the [DataClass] or
/// explicitly to absent on the [UpdateCompanion]), and a default value for
/// the field exists, that default value will be used. Otherwise, the field
/// will be reset to null. This behavior is different to [update], which simply
/// ignores such fields without changing them in the database.
Future<void> bulkReplace(Iterable<Insertable<D>> entities) {
return $state.db
.batch((b) => b.replaceAll($state._tableAsTableInfo, entities));
}
}