@edonec/indexed-db-class
Version:
An easy to use IndexedDb class, (post,put,delete and get) data easily from your indexedDb storage
56 lines (41 loc) • 1.07 kB
Markdown
# /indexed-db-class
to install
type
```bash
yarn add /indexed-db-class
```
or
```bash
npm install /indexed-db-class
```
## Usage
init the Class like so
```js
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
```js
// 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');
```