Yet another indexedDB facade. Supports callbacks and promises API.
$ npm install --save mlasq
With promises:
import mlasq from 'mlasq';
// create database and storage
async function doSometing() {
const db = mlasq('My DB', [ 'horses', 'cats' ]);
// put, get, count, remove etc.
const cats = db.store('cats');
const key = await cats.put('burek', {
name: 'burek',
age: 3
});
assert.equal(key, 'burek');
// close and remove db
await db.close();
console.log('closed now');
await db.remove();
console.log('all stores removed now');
}
All methods are asyn - that is a Promise
is returned that resolves to the result.
These are the object store methods:
Puts item
under the key
. Returns the key
.
Retrieves item
identified by key
.
Retrieves all items in the store.
Retrieves all keys in the store.
Upserts item: if item identified by key
already exists it is merged (using Onject.assign
) with the passed item
.
Returns the key
and the updated value of the item.
Removes item identified by the key
.
Counts number of items in store.
Clears the store: removes all the items.
MIT © Damian Krzeminski