Skip to content

An tiny, async, easy to use, fully typed indexedDB library

License

Notifications You must be signed in to change notification settings

westhide/async-idb

Repository files navigation

Async-idb

An tiny, async, easy to use, fully typed indexedDB library

Features

  • Auto wrap IDBRequest to async result, get result elegant through await

Installation

Using npm

npm install async-idb

Using pnpm

pnpm install async-idb

Then new Class IndexedDB in your project:

import { IndexedDB } from 'async-idb';

const idb = new IndexedDB(
  name: string; // you indexedDB name
  schemas: [
    {
      name: /* store name */,
      // primary key options
      options: {
        autoIncrement: boolean /* is autoIncrement */,
        keyPath: string | string[] /* primary keyPath */
        },
      // indexs you want to create
      indexes: [
        { name: /* index name */, keyPath:/* index keyPatch */  }
        ...
        ],
    },
    ...
  ],
  // eventlistener to indexedDB open request
  events: {
    onsuccess() {/*  */},
    onupgradeneeded() {/*  */},
    onversionchange() {/*  */},
    onclose() {/*  */},
    onblocked() {/*  */},
    onerror() {/*  */},
  },
  preset: {
    isDropDatabaseIfExist: false,
    isAutoCreateStore: true,
    // is auto init database
    isAutoInit: true, /* if set false,
                        indexedDB will not create until you call
                        await idb.init()
                        */
  },
)

Api

About

An tiny, async, easy to use, fully typed indexedDB library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published