From 1a68efce584f10a09d31f32421cefd6371ff0d77 Mon Sep 17 00:00:00 2001 From: Moshe Dicker Date: Wed, 17 Apr 2024 13:54:26 -0400 Subject: [PATCH] Add bulk replace --- drift/lib/src/runtime/manager/manager.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drift/lib/src/runtime/manager/manager.dart b/drift/lib/src/runtime/manager/manager.dart index 446e69b7..ba366487 100644 --- a/drift/lib/src/runtime/manager/manager.dart +++ b/drift/lib/src/runtime/manager/manager.dart @@ -564,4 +564,16 @@ abstract class RootTableManager< Future replace(Insertable 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 bulkReplace(Iterable> entities) { + return $state.db + .batch((b) => b.replaceAll($state._tableAsTableInfo, entities)); + } }