How to use the pouchdb.resetAllDbs function in pouchdb

To help you get started, we’ve selected a few pouchdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xMartin / grouptabs / src / db / tabidpersistor.ts View on Github external
export const migrateFromPouchDbAllDbsToLocalStorage = async () => {
  if (localStorage.getItem(KEY) !== null) {
    return;
  }

  try {
    // @ts-ignore
    const dbNames: string[] = await PouchDB.allDbs();
    const tabIds = dbNames.map((dbName) => dbName.substring(4));  // strip "tab/"
    localStorage.setItem(KEY, JSON.stringify(tabIds));
    console.info(`Migrated ${tabIds.length} tab(s) to local storage: ${tabIds.join(', ')}.`);
    try {
      // @ts-ignore
      await PouchDB.resetAllDbs();
    } catch (error) {
      console.error('Error destroying PouchDB.allDbs:');
      console.error(error);
    }
  } catch (error) {
    if (error.name !== 'indexed_db_went_bad') {
      console.warn('Error loading previously used tabs.');
      console.error(error);
      console.error('Could not fetch PouchDB\'s allDbs while trying to migrate to local storage.');
    }
  }
}