rauricoste-db-storage
v0.0.8
Published
Summary ====
Downloads
3
Readme
Summary
This library provides a database-like storage for the browser using HTML5 storage and databases features. This library has been developped with ES6 features, so you need to use a build tool such as browserify if you run it in an ES6 uncompatible browser.
3 implementations are provided, based on :
- IndexedDB
- LocalStorage
- Memory (not persistent across browser reload)
Usage
const DbStorage = require("rauricoste-db-storage");
// choose one :
const MyStorageClass = DbStorage.IndexedDbStorage;
const MyStorageClass = DbStorage.LocalStorage;
const MyStorageClass = DbStorage.InMemoryStorage;
const name = "myItems";
const storage = new MyStorageClass(name, options);
if (!storage.isSupported()) {
throw new Error("DbStorage is not supported !");
}
return storage.save("user", {
name: "rauricoste"
}).then(() => {
return storage.get("user");
}).then(item => {
/*
item = {
name: "rauricoste"
}
*/
}).catch(err => {
console.error(err);
})