0.0.4 • Published 4 years ago
persistent-store v0.0.4
persistent-store
Simplify how to use IndexedDB
This library uses the IndexedDB library under the hood and makes it easy to use.
Installation
npm install persistent-store --save
yarn add persistent-store
Boot Options
In the PersistentStore class there is a static crateStore method that must be called before any interaction with the database. This method will initialize the bank with the settings you enter.
import PersistentStore from 'persistent-store'
// `db_name` string containing the database name
// `db_version` integer containing the version of the database
// `db_collections` list containing all database collections and their settings
PersistentStore.crateStore('project', 1, [
// db_collections
// `collection_name` string containing the collection name
// `collection_key` string containing the key to access each object in the collection
// `collection_increment` boolean containing the rule for auto increment. In true case the bank itself will add a value to the object's key
{ name: 'users', key: 'index', increment: true },
...
])
PersistentStore API
Request methods allowed.
store.count(collection): Promise
store.clear(collection): Promise
store.get(collection, key): Promise
store.getAll(collection): Promise<T[]>
store.getAllKeys(collection): Promise<(string | number)[]>
store.add(collection, value): Promise<string | number>
store.addMany(collection, data): Promise<(string | number)[]>
store.update(collection, value): Promise
store.updateMany(collection, data): Promise
store.delete(collection, key): Promise
store.deleteMany(collection, keys): Promise
Example of Use
import PersistentStore from 'persistent-store'
const store = new PersistentStore('project')
const users = await store.getAll('users')
...
Credits
License
MIT