Dexie.js icon indicating copy to clipboard operation
Dexie.js copied to clipboard

Duplicate DB

Open tobiasBora opened this issue 1 year ago • 1 comments

Is there a way to duplicate a full database? I can't find how to do.

tobiasBora avatar Apr 28 '24 15:04 tobiasBora

For now I found a workaround with this (will work once https://github.com/dexie/Dexie.js/pull/1973 is merged)

  let duplicateFile = async (fileUuid : string) => {
    // I can't find how to duplicate, let's import + export in one go
    try {
      const db = await new Dexie(fileUuid).open();
      const blob = await db.export({prettyJson: true});
      await Dexie.import(blob, {
        getNewDatabaseName: async (databaseName) => {
          return uuidv4();
        }
      });
    } catch (error) {
      console.error(''+error);
    };
  };

not sure if there is a cleaner solution.

tobiasBora avatar Apr 29 '24 23:04 tobiasBora