databaseMerge function

Future<void> databaseMerge(
  1. Database db, {
  2. required Database sourceDatabase,
  3. List<String>? storeNames,
})

Merge a database with an existing source database.

Existing records are removed.

if storeNames is not specified, it handles stores from both the source and destination database.

Implementation

Future<void> databaseMerge(
  Database db, {
  required Database sourceDatabase,
  List<String>? storeNames,
}) async {
  var names =
      storeNames ??
      List.from(
        Set.from(getNonEmptyStoreNames(db))
          ..addAll(Set.from(getNonEmptyStoreNames(sourceDatabase))),
      );
  await db.transaction((transaction) async {
    for (var store in names) {
      await txnMergeStore(
        transaction,
        sourceDatabase: sourceDatabase,
        storeName: store,
      );
    }
  });
}