tekartik / sembast.dart

Simple io database
BSD 2-Clause "Simplified" License
763 stars 63 forks source link

how to rename a store? #377

Open jonasbernardo opened 2 months ago

alextekartik commented 2 months ago

There is unfortunately no way to rename a store. You have to copy/delete all the records using something like:

// old store
var store1 = intMapStoreFactory.store('store1');
// new store
var store2 = intMapStoreFactory.store('store2');
await db.transaction((txn) async {
  /// Read all records from store1 and write them to store2
  var records = await store1.find(txn);
  for (var record in records) {
    await store2.record(record.key).put(txn, record.value);
    // Delete existing record
    await store1.record(record.key).delete(txn);
  }
});
jonasbernardo commented 2 months ago

Thanks for the answer, I'm going to start using seambast in my projects