How to use the idb.open function in idb

To help you get started, we’ve selected a few idb 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 torch2424 / picoDeploy / src / providers / pico-db / pico-db.ts View on Github external
initialize() {
    // Set our defaults
    const dbName = '/user_data';
    const objectStoreName = 'FILE_DATA';
    const cartDataName = picoDeployConfig.dbWatcher.cartDataName;
    const cartDataKey = `/user_data/cdata/${cartDataName}.p8d.txt`;
    this.cartDataKey = cartDataKey;


    // pico 8 idb version is 21
    const dbPromise = idb.open(dbName, 21, upgradeDB => {
      //TODO: Handle Upgrade
      console.log('Pico-db: Upgrading db by creating the object store for pico-8', upgradeDB);

      // Create the object store
      upgradeDB.createObjectStore(objectStoreName);
    });

    // Only need the get functionality of idbKeyval
    // https://github.com/jakearchibald/idb
    this.idbKeyval = {
      get(key) {
        return dbPromise.then(db => {
          if(db) {
            return db.transaction(objectStoreName)
              .objectStore(objectStoreName).get(key);
          }
github lifechurch / melos / nodejs / packages / youversion-api-redux / src / indexdb.js View on Github external
const DB_NAME = 'YouVersion'
const VERSION = 1

// schemas




// database functions
const createStore = (upgradeDB, storeName, options) => {
	if (!upgradeDB.objectStoreNames.contains(storeName)) {
		upgradeDB.createObjectStore(storeName, options);
	}
}

const dbPromise = idb.open(DB_NAME, VERSION, (upgradeDB) => {
	// upgradeCallback is called if version is greater than the version last opened
	createStore(upgradeDB, 'plans', { keyPath: 'id' })
})

const database = {
	get({ storeName, key }) {
		return dbPromise.then((db) => {
			return db.transaction(storeName)
        .objectStore(storeName).get(key)
		})
	},
	set({ storeName, key = null, val }) {
		return dbPromise.then((db) => {
			const tx = db.transaction(storeName, 'readwrite')
			tx.objectStore(storeName).put(val, key)
			return tx.complete
github mike-works / pwa-fundamentals / client / data / db.js View on Github external
export function getDb() {
  return idb.open('FEGrocerDB', 3, upgrade => {
    switch(upgrade.oldVersion) {
    case 0: // New database
      upgrade.createObjectStore('grocery-items', {keyPath: 'id'});
    case 1: // Upgrade from v1 to v2
      upgrade.createObjectStore('cart', { keyPath: 'groceryItem.id'})
    case 2: // Upgrade from v3 to v3
      let tx = upgrade.transaction;
      let giStore = tx.objectStore('grocery-items');
      giStore.createIndex('categoryIndex', 'category');
    }
  });
}
/* eslint-enable no-case-declarations */
github GoogleChrome / workbox / lib / idb-helper.js View on Github external
_getDb() {
    if (this._dbPromise) {
      return this._dbPromise;
    }

    this._dbPromise = idb.open(this._name, this._version, (upgradeDB) => {
      upgradeDB.createObjectStore(this._storeName);
    })
    .then((db) => {
      return db;
    });

    return this._dbPromise;
  }
github GoogleChrome / workbox / packages / workbox-cache-expiration / src / lib / cache-expiration.js View on Github external
async getDB({cacheName} = {}) {
    isType({cacheName}, 'string');

    const idbId = `${idbName}-${cacheName}`;
    if (!this._dbs.has(idbId)) {
      const openDb = await idb.open(idbId, idbVersion, (upgradeDB) => {
        const objectStore = upgradeDB.createObjectStore(cacheName,
          {keyPath: urlPropertyName});
        objectStore.createIndex(timestampPropertyName, timestampPropertyName,
          {unique: false});
      });
      this._dbs.set(idbId, openDb);
    }

    return this._dbs.get(idbId);
  }
github wtulloch / Blazor.IndexedDB / Blazor.IndexedDB.JS / src / indexedDbBlazor.ts View on Github external
public openDb = async (data: IDbStore, instanceWrapper: IDotNetInstanceWrapper): Promise => {
        const dbStore = data;
        //just a test for the moment
        this.dotnetCallback = (message: string) => {
            instanceWrapper.instance.invokeMethod(instanceWrapper.methodName, message);
        }

        if (this.dbInstance) {
            await this.dbInstance.close();
        }
            this.dbInstance =  await idb.open(dbStore.dbName, dbStore.version, upgradeDB => {
                this.upgradeDatabase(upgradeDB, dbStore);
            });
        return `IndexedDB ${data.dbName} opened`;
    }
github google-developer-training / pwa-ecommerce-demo / solution / app / scripts / modules / idb-storage.js View on Github external
_open() {
    return this._dbPromise = idb.open(this._id, 1, upgradeDB => {
      upgradeDB.createObjectStore(CART_STORE, {autoIncrement: true});
    });
  }
github manusa / isotope-mail / client / src / services / indexed-db.js View on Github external
function _openDatabase() {
  return idb.open(DATABASE_NAME, DATABASE_VERSION,
    upgradeDb => {
      if (!upgradeDb.objectStoreNames.contains(STATE_STORE)) {
        upgradeDb.createObjectStore(STATE_STORE, {keyPath: 'key'});
      }
      if (!upgradeDb.objectStoreNames.contains(MESSAGE_CACHE_STORE)) {
        const messageCacheStore = upgradeDb.createObjectStore(MESSAGE_CACHE_STORE, {keyPath: 'key'});
        messageCacheStore.createIndex('userId', 'userId', {unique: false});
      }
      if (!upgradeDb.objectStoreNames.contains(NEW_MESSAGE_STORE)) {
        upgradeDb.createObjectStore(NEW_MESSAGE_STORE, {keyPath: 'key'});
      }
    });
}

idb

A small wrapper that makes IndexedDB usable

ISC
Latest version published 6 months ago

Package Health Score

83 / 100
Full package analysis