npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@isdk/idb

v0.1.0

Published

very tiny promise-based IndexedDB wrapper

Downloads

1

Readme

Simple IndexedDB Wrapper

This is a TypeScript/JavaScript wrapper library for IndexedDB, providing a simplified and convenient API for working with IndexedDB databases.

Features

  • Easy-to-use methods for performing common IndexedDB operations, such as adding, retrieving, updating, and deleting data.
  • Support for creating and deleting indexes to enhance data querying and retrieval.
  • Abstraction of transactions and object stores, simplifying the management of database transactions.
  • Promisified methods for asynchronous operations, allowing for better control flow and error handling.
  • Migrations support for managing database schema changes.

Getting Started

Installation

You can install the library via npm:

npm install @isdk/idb

Usage

To use the IndexedDB wrapper in your project, import the necessary classes and functions:

import { IndexedDBDatabase, IndexedDBIndex, IndexedDBStore, IndexedDBTransaction } from  '@isdk/idb'; 

Create an instance of IndexedDBDatabase to interact with a database and manage migrations:

const database = new IndexedDBDatabase();
// Open the database
await database.open(dbName, version, migrations);

The dbName parameter is the name of the database, version is the desired version of the database, and migrations is an array of migration objects.

Migration using callback functions

const migrations = [
  {
    version: 1,
    upgrade(db, transaction) {
      const objectStore = db.createObjectStore('books', { keyPath: 'id' });
      objectStore.createIndex('title', 'title', { unique: false });
    },
    rollback(db, transaction) {
      db.deleteObjectStore('books');
    }
  },
  {
    version: 2,
    upgrade(db, transaction) {
      const objectStore = transaction.objectStore('books');
      objectStore.createIndex('author', 'author', { unique: false });
    },
    rollback(db, transaction) {
      const objectStore = transaction.objectStore('books');
      objectStore.deleteIndex('author');
    }
  }
];

Migration using stores

const migrations = [
  { 
    version: 1, 
    stores: [
      {
        name: 'books', keyPath: 'id', 
        indexes: [
          {name: 'title', keyPath: 'title', options: {unique: false}}
        ] 
      }
    ],
  },
  {
    version: 2, 
    // add indexes to exists store
    indexes: [
      {
        store: 'books',
        name: 'ixCategory',
        keyPath: 'category', options: {unique: false}
      }
    ]
  }
];

Mixed migration using both callback functions and stores

const migrations = [
  {
    version: 1,
    stores: 'books',
    upgrade: (db, transaction) => transaction.objectStore('books').createIndex('title', 'title', { unique: false })
  }
];

Perform operations on the database using the provided methods:

const database = new IndexedDBDatabase();

// Open the database
await database.open(dbName, version, migrations);

// get an object store
const store = database.getObjectStore(storeName);

// Perform operations on the object store
await store.add(key, value);
const data = await store.get(key);
await store.set(key, updatedValue);
await store.remove(key);

For more detailed examples and usage instructions, please refer to the API documentation section.

API Documentation

Detailed API documentation and examples can be found in the docs folder.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.