How to use the idb.openDB 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 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 browserpass / browserpass-extension / src / background.js View on Github external
login.recent.when = Date.now();
    settings.recent[sha1(settings.origin + sha1(login.store.id + sha1(login.login)))] =
        login.recent;

    // save to local storage
    localStorage.setItem("recent", JSON.stringify(settings.recent));

    // a new entry was added to the popup matching list, need to refresh the count
    if (!login.inCurrentHost && login.recent.count === 1) {
        updateMatchingPasswordsCount(settings.tab.id, true);
    }

    // save to usage log
    try {
        const DB_VERSION = 1;
        const db = await idb.openDB("browserpass", DB_VERSION, {
            upgrade(db) {
                db.createObjectStore("log", { keyPath: "time" });
            }
        });
        await db.add("log", { time: Date.now(), host: settings.origin, login: login.login });
    } catch {
        // ignore any errors and proceed without saving a log entry to Indexed DB
    }
}
github eclipse-theia / theia / packages / monaco / src / browser / monaco-theming-service.ts View on Github external
*/
    uiTheme?: monaco.editor.BuiltinTheme;
    description?: string;
    /**
     * Follow https://code.visualstudio.com/api/extension-guides/color-theme#create-a-new-color-theme to create a custom theme.
     */
    json: any
    /**
     * Themes can include each other. It specifies how inclusions should be resolved.
     */
    includes?: { [includePath: string]: any }
}

let monacoDB: Promise | undefined;
if ('indexedDB' in window) {
    monacoDB = idb.openDB('theia-monaco', 1, {
        upgrade: db => {
            if (!db.objectStoreNames.contains('themes')) {
                db.createObjectStore('themes', { keyPath: 'id' });
            }
        }
    });
}

@injectable()
export class MonacoThemingService {

    @inject(FileSystem)
    protected readonly fileSystem: FileSystem;

    // tslint:disable-next-line:no-any
    register(theme: MonacoTheme, pending: { [uri: string]: Promise } = {}): Disposable {
github ggoodman / velcro / packages / runtime / src / idb_cache.ts View on Github external
export function createCache(name: string, predicate?: CachePredicate): Runtime.Cache {
  const idbPromise = openDB(name, IDB_CACHE_VERSION, {
    async upgrade(db, oldVersion, newVersion, tx) {
      log('Upgrading cache from version %s to %s', oldVersion, newVersion);

      switch (oldVersion) {
        case 0:
          db.createObjectStore(Runtime.CacheSegment.Registration);
          db.createObjectStore(Runtime.CacheSegment.Resolution);
        case 1:
          await tx.objectStore(Runtime.CacheSegment.Registration).clear();
          await tx.objectStore(Runtime.CacheSegment.Resolution).clear();
      }
    },
  });

  return {
    clear(segment?: Runtime.CacheSegment) {
github dap-ps / discover / src / common / data / database.js View on Github external
function open() {
  return openDB(DB_NAME, 1, {
    upgrade(db) {
      db.createObjectStore(DB_STORE_DAPPS, {
        keyPath: 'id',
      })
    },
  })
}
github morrys / wora / packages / cache-persist / src / idbstorage.ts View on Github external
static create(options: {
        name?: string,
        storeNames?: string[],
        version?: number,
        onUpgrade?: OnUpgrade
    }): any[] {

        const {
            name = 'cache',
            storeNames = ['persist'],
            version = 1,
            onUpgrade = (db, oldVersion, newVersion, transaction) => { }
        } = options;

        const dbPromise = openDB(name, version, {
            upgrade(dbPromise, oldVersion, newVersion, transaction) {
                if (newVersion === 1) {
                    storeNames.forEach(storeName => {
                        dbPromise.createObjectStore(storeName);
                    });
                }
                onUpgrade(dbPromise, oldVersion, newVersion, transaction);

            }
        })

        const listItems = storeNames.map((value) => (
            createIdbStorage(dbPromise, value)
        ));

        return listItems;
github allartk / leaflet.offline / src / TileManager.js View on Github external
import L from 'leaflet';
import { openDB } from 'idb';

const tileStoreName = 'tileStore';
const urlTemplateIndex = 'urlTemplate';

const dbPromise = openDB('leaflet.offline', 1, {
  upgrade(db) {
    const tileStore = db.createObjectStore(tileStoreName, {
      keyPath: 'key',
    });
    tileStore.createIndex(urlTemplateIndex, 'urlTemplate');
    tileStore.createIndex('z', 'z');
  },
});

/**
 *
 * @typedef {Object} tileInfo
 * @property {string} key storage key
 * @property {string} url resolved url
 * @property {string} urlTemplate orig url, used to find tiles per layer
 * @property {string} x left point of tile

idb

A small wrapper that makes IndexedDB usable

ISC
Latest version published 6 months ago

Package Health Score

83 / 100
Full package analysis