How to use idb - 10 common examples

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 gadicc / gongo / gongo-client / src / gongo.js View on Github external
async idbOpen() {
    log.debug('Opening IDB "gongo" database');
    this.idbIsOpen = true;

    // idbDbVersion is (purposefully) undefined for initial open
    this.idbPromise = openDb('gongo', this.idbDbVersion, upgradeDB => {
      log.info('Upgrading IDB "gongo" database v' + this.idbDbVersion);

      for (let name of upgradeDB._db.objectStoreNames)
        if (!this.collections.has(name))
          upgradeDB.deleteObjectStore(name);

      for (let [name] of this.collections)
        if (!upgradeDB._db.objectStoreNames.contains(name))
          upgradeDB.createObjectStore(name);
    });

    this.idbPromise.catch(e => {
      console.log(e.message);
      throw e;
    })
github IBM / tfjs-web-app / src / pages / Classify.js View on Github external
async componentDidMount() {
    if (('indexedDB' in window)) {
      try {
        this.model = await tf.loadLayersModel('indexeddb://' + INDEXEDDB_KEY);

        // Safe to assume tensorflowjs database and related object store exists.
        // Get the date when the model was saved.
        try {
          const db = await openDB(INDEXEDDB_DB, 1, );
          const item = await db.transaction(INDEXEDDB_STORE)
                               .objectStore(INDEXEDDB_STORE)
                               .get(INDEXEDDB_KEY);
          const dateSaved = new Date(item.modelArtifactsInfo.dateSaved);
          await this.getModelInfo();
          console.log(this.modelLastUpdated);
          if (!this.modelLastUpdated  || dateSaved >= new Date(this.modelLastUpdated).getTime()) {
            console.log('Using saved model');
          }
          else {
            this.setState({
              modelUpdateAvailable: true,
              showModelUpdateAlert: true,
            });
          }
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 sikidamjanovic / cowrite / node_modules / @firebase / installations / dist / index.esm.js View on Github external
function getDbPromise() {
    if (!dbPromise) {
        dbPromise = openDb(DATABASE_NAME, DATABASE_VERSION, function (upgradeDB) {
            // We don't use 'break' in this switch statement, the fall-through
            // behavior is what we want, because if there are multiple versions between
            // the old version and the current version, we want ALL the migrations
            // that correspond to those versions to run, not only the last one.
            // eslint-disable-next-line default-case
            switch (upgradeDB.oldVersion) {
                case 0:
                    upgradeDB.createObjectStore(OBJECT_STORE_NAME);
            }
        });
    }
    return dbPromise;
}
/** Assigns or overwrites the record for the given key with the given value. */
github maierj / fastlane-action / node_modules / @firebase / installations / dist / index.cjs.js View on Github external
function getDbPromise() {
    if (!dbPromise) {
        dbPromise = idb.openDb(DATABASE_NAME, DATABASE_VERSION, function (upgradeDB) {
            // We don't use 'break' in this switch statement, the fall-through
            // behavior is what we want, because if there are multiple versions between
            // the old version and the current version, we want ALL the migrations
            // that correspond to those versions to run, not only the last one.
            // eslint-disable-next-line default-case
            switch (upgradeDB.oldVersion) {
                case 0:
                    upgradeDB.createObjectStore(OBJECT_STORE_NAME);
            }
        });
    }
    return dbPromise;
}
/** Assigns or overwrites the record for the given key with the given value. */
github maierj / fastlane-action / node_modules / @firebase / installations / dist / index.esm2017.js View on Github external
function getDbPromise() {
    if (!dbPromise) {
        dbPromise = openDb(DATABASE_NAME, DATABASE_VERSION, upgradeDB => {
            // We don't use 'break' in this switch statement, the fall-through
            // behavior is what we want, because if there are multiple versions between
            // the old version and the current version, we want ALL the migrations
            // that correspond to those versions to run, not only the last one.
            // eslint-disable-next-line default-case
            switch (upgradeDB.oldVersion) {
                case 0:
                    upgradeDB.createObjectStore(OBJECT_STORE_NAME);
            }
        });
    }
    return dbPromise;
}
/** Assigns or overwrites the record for the given key with the given value. */
github maierj / fastlane-action / node_modules / @firebase / installations / dist / index.esm.js View on Github external
function getDbPromise() {
    if (!dbPromise) {
        dbPromise = openDb(DATABASE_NAME, DATABASE_VERSION, function (upgradeDB) {
            // We don't use 'break' in this switch statement, the fall-through
            // behavior is what we want, because if there are multiple versions between
            // the old version and the current version, we want ALL the migrations
            // that correspond to those versions to run, not only the last one.
            // eslint-disable-next-line default-case
            switch (upgradeDB.oldVersion) {
                case 0:
                    upgradeDB.createObjectStore(OBJECT_STORE_NAME);
            }
        });
    }
    return dbPromise;
}
/** Assigns or overwrites the record for the given key with the given value. */
github sikidamjanovic / cowrite / node_modules / @firebase / installations / dist / index.esm2017.js View on Github external
function getDbPromise() {
    if (!dbPromise) {
        dbPromise = openDb(DATABASE_NAME, DATABASE_VERSION, upgradeDB => {
            // We don't use 'break' in this switch statement, the fall-through
            // behavior is what we want, because if there are multiple versions between
            // the old version and the current version, we want ALL the migrations
            // that correspond to those versions to run, not only the last one.
            // eslint-disable-next-line default-case
            switch (upgradeDB.oldVersion) {
                case 0:
                    upgradeDB.createObjectStore(OBJECT_STORE_NAME);
            }
        });
    }
    return dbPromise;
}
/** Assigns or overwrites the record for the given key with the given value. */

idb

A small wrapper that makes IndexedDB usable

ISC
Latest version published 12 months ago

Package Health Score

76 / 100
Full package analysis