0.0.7 • Published 11 months ago

simple-idb-easy v0.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Simple Idb Easy

Simple Idb Easy is a straightforward npm package designed to simplify common operations with IndexedDB. It provides a clean and easy-to-use API for initializing the database, setting up schema, and performing CRUD operations.

Features

  • Database Initialization: dbInit for initializing the database.
  • Schema Setup: setupSchema to define the database structure.
  • Version Management: setVersion to manage database versions.
  • CRUD Operations:
    • insert to add records.
    • update to modify existing records.
    • deleteRecord to remove records.
    • get to retrieve a single record.
    • getAll to fetch all records.

Installation

To install the package, run:

npm install simple-idb-easy

Usage

Here’s a basic example of how to use simple-idb-easy with async/await:

import { simpleIdb } from "simple-idb-easy";

async function example() {
  let schemas: SchemaFuncs = {
    myObjectStore: function (db: IDBPDatabase): any {
      let dbName = "myObjectStore";
      if (!db.objectStoreNames.contains(dbName)) {
        let store = db.createObjectStore(dbName, { keyPath: "id" });
      }
    },
  };

  // Set the database version
  simpleIdb.setVersion(1);

  // Set the schema
  simpleIdb.setupSchema(schemas);
  await simpleIdb.dbInit();

  // Insert a record
  await simpleIdb.insert("myObjectStore", {
    id: 1,
    name: "Sample Record",
  });

  // Update a record
  await simpleIdb.update("myObjectStore", {
    id: 1,
    name: "Updated Record",
  });

  // Get a single record
  const record = await simpleIdb.get("myObjectStore", 1);
  console.log(record);

  // Get all records
  const records = await simpleIdb.getAll("myObjectStore");
  console.log(records);

  // Delete a record
  await simpleIdb.deleteRecord("myObjectStore", 1);
}

await example();

Third-Party Licenses

This project uses the following third-party packages:

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago