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

persistdb

v0.1.0

Published

A lightweight database solution for browsers using IndexedDB

Downloads

22

Readme

PersistDB

PersistDB is a TypeScript package that provides a convenient interface for working with IndexedDB in web applications. It allows you to perform common operations such as adding, updating, removing, and retrieving data from an IndexedDB database.

Installation

You can install the package via npm:

npm install persistdb

Usage

import PersistDB from 'persistdb';

const db = new PersistDB('MyDatabase', 'MyStore');

Methods

Example : add(item: T): Promise

  • Adds an item to the IndexedDB store.
  • item: The item to be added.
  • Returns: A promise that resolves with the generated key (ID) of the added item.
// Adding an object

db.add({ id: 1, name: 'Item 1', data: [1, 2, 3] })
  .then(id => {
    console.log('Item added with id:', id);
  })
  .catch(error => {
    console.error('Error adding item:', error);
  });

Example : update(id: number, item: T): Promise

  • Updates an existing item in the IndexedDB store.
  • id: The ID of the item to update.
  • item: The updated item.
  • Returns: A promise that resolves when the item is successfully updated.
// Updating an item

db.update(1, { id: 1, name: 'Updated Item 1', data: [4, 5, 6] })
  .then(() => {
    console.log('Item updated');
  })
  .catch(error => {
    console.error('Error updating item:', error);
  });

Example : remove(id: number): Promise

  • Removes an item from the IndexedDB store.
  • id: The ID of the item to remove.
  • Returns: A promise that resolves when the item is successfully removed.
// Removing an item

db.remove(1)
  .then(() => {
    console.log('Item removed');
  })
  .catch(error => {
    console.error('Error removing item:', error);
  });

Example : get(id: number): Promise<T | undefined>

  • Retrieves an item from the IndexedDB store by its ID.
  • id: The ID of the item to retrieve.
  • Returns: A promise that resolves with the retrieved item, or undefined if not found.
// Getting an item by ID

db.get<{ id: number; name: string; data: number[] }>(1)
  .then(item => {
    console.log('Retrieved item:', item);
  })
  .catch(error => {
    console.error('Error getting item:', error);
  });

Example : getAll(): Promise<T[]>

  • Retrieves all items from the IndexedDB store.

  • Returns: A promise that resolves with an array of all items in the store.

// Getting all items

db.getAll<{ id: number; name: string; data: number[] }>()
  .then(items => {
    console.log('All items:', items);
  })
  .catch(error => {
    console.error('Error getting all items:', error);
  });

Feel free to customize the README according to your package's specific features and usage instructions.