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

@justinwwolcott/ez-index-db

v5.0.0

Published

Easier way to work with indexDB for 90pct of use cases

Downloads

2

Readme

EZindexDB & SynthEzIndexDB

Overview

EZindexDB is a class designed to simplify interactions with IndexedDB, providing a set of methods to perform various database operations. SynthEzIndexDB is a class that simulates interactions with IndexedDB using in-memory storage, which can be useful for testing purposes.

EZindexDB

Description

A class to simplify interactions with IndexedDB.

Methods

start(database, table, indexes)

  • Description: Initializes a connection to the database or creates it if it doesn't exist.
  • Parameters:
    • database (string): The name of the database.
    • table (string): The name of the table (object store).
    • indexes (Array): An array of index names to be created (optional).
  • Returns: Promise - Resolves to true if successful.

creates(table, data)

  • Description: Adds a record to the database if it doesn't exist. Throws an error if the record already exists.
  • Parameters:
    • table (string): The name of the table (object store).
    • data (Object): The data to be added.
  • Returns: Promise - Resolves to the key of the added record.

reads(table, id)

  • Description: Retrieves a record from the database by its ID.
  • Parameters:
    • table (string): The name of the table (object store).
    • id (IDBValidKey): The ID of the record to retrieve.
  • Returns: Promise - Resolves to the retrieved record.

updates(table, data)

  • Description: Updates an existing record in the database. Throws an error if the record doesn't exist.
  • Parameters:
    • table (string): The name of the table (object store).
    • data (Object): The data to update.
  • Returns: Promise - Resolves to the key of the updated record.

upserts(table, data)

  • Description: Inserts or updates a record in the database.
  • Parameters:
    • table (string): The name of the table (object store).
    • data (Object): The data to insert or update.
  • Returns: Promise - Resolves to the key of the inserted or updated record.

deletes(table, id)

  • Description: Deletes a record from the database by its ID.
  • Parameters:
    • table (string): The name of the table (object store).
    • id (IDBValidKey): The ID of the record to delete.
  • Returns: Promise - Resolves to true if the deletion was successful.

searches(table, field, value)

  • Description: Searches for records in the database by a specified field and value.
  • Parameters:
    • table (string): The name of the table (object store).
    • field (string): The name of the field to search by.
    • value (any): The value to search for.
  • Returns: Promise - Resolves to an array of matching records.

getAll(table)

  • Description: Retrieves all records from a table.
  • Parameters:
    • table (string): The name of the table (object store).
  • Returns: Promise - Resolves to an array of all records.

countRecords(table)

  • Description: Counts the number of records in a table.
  • Parameters:
    • table (string): The name of the table (object store).
  • Returns: Promise - Resolves to the count of records.

SynthEzIndexDB

Description

A class to simulate interactions with IndexedDB using in-memory storage.

Methods

The methods for SynthEzIndexDB are similar to those of EZindexDB, but operate on in-memory storage. Refer to the methods listed under EZindexDB for their descriptions, parameters, and return values.

Usage

// Instantiate the DB
let ez = new EZindexDB();

// List any of the fields we might want to search on that aren't "id"
await ez.start("company","people",["name"]);

// Demonstration of adding people to our DB
await ez.creates("people",{"id": "1", "salary": 12, "name": "STEVE"});
await ez.creates("people",{"id": "2", "salary": 12, "name": "EDDY"});
await ez.creates("people",{"id": "3", "salary": 12, "name": "JOE"});
await ez.creates("people",{"id": "4", "salary": 13, "name": "JOE"});

// Find everybody named "JOE"
let data = await ez.searches("people","name", "JOE");

// Set Joe's Salary to 12_000
await ez.updates("people",{"id": "3", "salary": 12_000});

// Make sure we can't 'upsert' a record
await ez.updates("people",{"id": "newb", "salary": 12_000});  // this one fails