Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

idb-javascript

victorqueiroz185MIT0.0.30TypeScript support: included

Installation

indexeddb, indexed-db, database, data, web, data-persistence

readme

idb-javascript

Installation

yarn add idb-javascript

Usage

Create your own database class

class RecordingDb extends Database<{
  recordingBlobParts: {
    recordingId: string;
    blob: Blob;
  };
  recordings: {
    id: string;
  };
}> {
  @boundMethod protected override onUpgradeNeeded(
    _: IDBVersionChangeEvent
  ): void {
    const db = this.request().result;
    const recordings = db.createObjectStore("recordings");
    recordings.createIndex("id", "id", {
      unique: true,
    });
    const recordingBlobParts = db.createObjectStore("recordingBlobParts");
    recordingBlobParts.createIndex("id", "id", {
      unique: true,
    });
  }
}

Put a new object on the store

const db = new RecordingDb(randomDbName(), 1);
expect(
  await db.transaction("recordings", "readwrite").objectStore("recordings").put(
    {
      id: "1",
    },
    "1"
  )
).to.be.equal("1");