1.0.5 • Published 6 years ago

idb-store v1.0.5

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

IndexedDB Promises ES6 Store Wrapper

ES6 class wrapper for creating and managing IndexedDB stores, built on top of jakearchibald idb lib.

Up and Running

npm install idb-store

Usage

const schemas = [
  {
    create: {
      name: 'item',
      options: {autoIncrement: true}
    },
    index: {
      name: 'myIndex',
      property: 'property',
      options: {unique: false}
    }
  }];

const DB = require('idb-store').DB;
const Store = require('idb-store').Store;

// Creates a new database.
DB.createDatabase('myDB', 1, schemas);

const db = new DB('myDB', 1);
const itemRepository = new Store('item', db);

// Creates a transactions and sets some data in the store.
itemRepository.set({ data: 42 })
  .then(itemRepository.getAll)
  .then(val => {
    console.log(val);
  });
});

// Opens a new connection and logs the database name.
db.open()
  .then(db.name)
  .then(name => {
    console.log('database name:', name);
  })
  .then(db.close)
});

DB

Static properties:

  • DB.hasSupport
  • DB.createDatabase
  • DB.deleteDatabase

db

Properties:

  • db.name
  • db.version
  • db.objectStoreNames

Methods:

  • db.close()
  • db.transaction()

Events:

  • onversionchange
  • onabort
  • onerror
  • onclose

Stores

Methods:

  • db[store].get()
  • db[store].set()
  • db[store].delete()
  • db[store].clear()
  • db[store].getAllKeys()
  • db[store].getAll()
  • db[store].count()
1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago