Add import/export support for a db

nponiros asked for this feature about 4 years ago — 5 comments

nponiros commented about 4 years ago Admin

Add support to export the contents of the database to a file and support to import from said file. This feature should probably be an external addon.

A few challenges:

  • saving binary data/blobs
  • importing the file when the database version or schema of the backup does not match the database version/schema of the installed db
  • data to display a progressbar


  • should the import try to merge changes or completely rebuild the db?
  • schema for the export. What do we have to include? Fild format?
  • should database access be blocked during the export?

See also https://github.com/dfahlander/Dexie.js/issues/391 and https://github.com/dfahlander/Dexie.js/issues/99

EDIT: This addon is now complete: https://github.com/dfahlander/Dexie.js/tree/master/addons/dexie-export-import

| Script47 commented about 4 years ago

I think this would be an excellent addition, if possible could it be exported to a JSON string which can be then imported again if need be?

sechel commented over 3 years ago

There are however values that cannot easily be exported, e.g. CryptoKeys. We would have to extract (if possible) the keys after the export to really create a backup.

dfahlander commented over 2 years ago Admin

Working on this feature as a dexie addon.

Will basically be used like this:

import Dexie from 'dexie';
import 'dexie-export-import';

// Import and create Dexie instance in one call:
const importedDb = await Dexie.import(blob);

// Import into existing db:
const db = new Dexie('dbname');
db.version(1).stores({foo: 'bar', ...});
await db.import(blob, [options]);

// Export:
const exportBlob = await importedDb.export();

Join the discussion!

with GitHub to comment