@edonec/indexed-db-class
v1.0.7
Published
An easy to use IndexedDb class, (post,put,delete and get) data easily from your indexedDb storage
Downloads
5
Readme
@edonec/indexed-db-class
to install
type
yarn add @edonec/indexed-db-class
or
npm install @edonec/indexed-db-class
Usage
init the Class like so
let db: IndexedDb;
// for SSR make sure the window is defined
if (typeof window !== 'undefined') {
db = new IndexedDb('Auth', [{ tableName: 'user', key: 'id' }]);
}
export { db };
and then make use of the functions within the db
object
// creatinga new table
await db.createTable('address', 'id');
// adding data to an existing table
await db.postData('address', {
/* ...some data */
});
// update existing data to an existing table or create it if not existe
await db.createOrUpdate('address', {
/* ...some data */
});
// update existing data to an existing table
await db.updateData('address', {
/* ...some data */
});
// delete a record from an existing table
db.deleteData('address', id);
// getting data
const data = (await db.getData) < string > ('user', 'some id that you previously sat');