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

esperodb

v1.0.5

Published

A TypeScript library for managing a local IndexedDB database.

Downloads

21

Readme

EsperoDB

EsperoDB is a TypeScript library for managing a local IndexedDB database.

Installation

npm install esperodb

Usage

import { EsperoDB } from 'esperodb';

// Example database structure
const dataStructure: any = [
  {
    'table1': [
      { indexes: [{ 'index1': { unique: false } }], primaryKey: 'id' },
    ],
  },
  {
    'table2': [
      // Table structure without indexes
    ],
  },
];
const dbVersion: number = 1;

// Create an instance of the local database
const db = new EsperoDB('myDatabase', dataStructure, dbVersion);

// Add data to a table
const dataToAdd = { id: 1, name: 'John Doe' };
db.addData('table1', dataToAdd)
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

// Update data in a table
const updatedData = { id: 1, name: 'Jane Doe' };
db.updateData('table1', updatedData)
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

// Retrieve data from a table by primary key
db.getData('table1', 1)
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

// Retrieve all data from a table
db.getAllData('table1')
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

// Search for data in a table by index
db.search('table1', 'index1', 'someValue')
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

// Delete data from a table by primary key
db.deleteData('table1', 1)
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

API

EsperoDB

Constructor

constructor(dbName: string, dataStructure: TableData, dbVersion?: number = 1);

Creates an instance of EsperoDB.

  • dbName: The name of the database.
  • dataStructure: The structure of the database including table names, indexes, and primary keys.
  • dbVersion: The version of the database (default: 1).

Methods

  • openDatabase(): Promise<IDBDatabase | null> Opens the IndexedDB database and creates or upgrades object stores based on the provided data structure.

  • addData(dbTable: string, data: Record<string, any>): Promise<string> Adds data to the specified table in the database.

  • updateData(dbTable: string, data: Record<string, any>): Promise<string> Updates data in the specified table in the database.

  • getData(dbTable: string, key: any): Promise<Record<string, any>> Retrieves data from the specified table based on the provided key.

  • getAllData(dbTable: string): Promise<Record<string, any>[]> Retrieves all data from the specified table in the database.

  • search(tableName: string, indexName: string, searchValue: any): Promise<Record<string, any>[]> Searches for records in a specified table based on a given index and value.

  • deleteData(dbTable: string, key: any): Promise<string> Deletes data from the specified table in the database.

  • getDataWithPagination(dbTable: string, currentPage: number, pageSize: number): Promise<{ isSuccess: boolean; results?: Record<string, any>[]; totalPages?: number; currentPage?: number; nextPage?: number | null; previousPage?: number | null; }> Retrieves paginated data from the specified table in the database, including information about total pages, current page, next page, and previous page.

  • searchByTag(tableName: string, searchField: string, keyword: string, currentPage: number, pageSize: number): Promise<{ isSuccess: boolean; results?: Record<string, any>[]; totalPages?: number; currentPage?: number; nextPage?: number | null; previousPage?: number | null; resultCount?: number | null; allCount?: number | null; pageLinks?: string[]; }>

    Searches for data in a table by a specified search field and keyword with pagination.

    • tableName: The name of the table to search.
    • searchField: The field in the table to search for.
    • keyword: The keyword to search for.
    • currentPage: The current page number for pagination.
    • pageSize: The number of items per page for pagination.

    Returns an object with search results, pagination details, and counts.

Notes

  • Ensure a good understanding of the data structure when creating the database.
  • Use the provided methods by EsperoDB to interact with the database asynchronously.

## Support

Owner: Mudey Formation (https://mudey.fr)

For questions or support, please contact [[email protected]].