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

@yobuligo/local-storage-db

v1.0.0

Published

Local Storage DB

Downloads

1

Readme

Local Storage DB

A light weight local storage db. Each database is stored in the local storage by the database name and prefix "db." (e.g. db.retrospective). It contains all tables of this database and currently the current auto incremented value per table. Each table and its data are stored in a separate entry in the local storage. The corresponding key contains the database as prefix followed by the table name (e.g. db.retrospective.boards). Each data type to be stored in a table must extend IRecord, which contains the property is and optional createdAt and changedAt.

Create database

A database can be created via class Database.

const db = new Database("demo");

Create table

A table can be added to a database by method define.

Create a database with table Person which contains records of type IPerson. The api automatically sets and updates createdAt and changedAt timestamps.

interface IPerson extends IRecord<number> {
  firstname: string;
  lastname: string;
}

const db = new Database("demo");
const Person = db.define<IPerson>("persons").build();

Create a database with table Person which contains records of type IPerson. The timestamp handling for createdAt and changedAt is disabled.

interface IPerson extends IRecord<number> {
  firstname: string;
  lastname: string;
}

const db = new Database("demo");
const Person = db.define<IPerson>("persons").build({ timestamps: false });

Create a database with table Person which contains records of type IPerson. The timestamp handling for createdAt and changedAt is enabled and each record gets an uuid id.

interface IPerson extends IRecord<string> {
  firstname: string;
  lastname: string;
}

const db = new Database("demo");
const Person = db
  .define<IPerson>("persons")
  .build({ timestamps: true, uuid: true });

Insert records

Inserts can be executed via function insert at the table.

Insert a new record to table Person and get the person object as return.

const person = Person.insert({ firstname: "Stacey", lastname: "Starfish" });

Insert new records and get the person objects as return.

const persons = Person.insert([
  { firstname: "Alex", lastname: "Ant" },
  { firstname: "Stacey", lastname: "Starfish" },
]);

Select records

Selects can be executed via function select at the table.

Return all records of table Person:

const persons = Person.select();

Return all records which match the where clause:

const persons = Person.select({ where: { id: 10 } });

Return a max limit of records which match the where clause

const persons = Person.select({ limit: 3, where: { firstname: "Stacey" } });

Update records

Updates can be executed via function update at the table.

Updates all records by setting firstname to Stacey.

const updateResult = Person.update({ firstname: "Stacey" });

Updates all records by setting firstname to Stacey and lastname to Starfish, which have an id lower than 10 or update nothing if not found.

const updateResult = Person.update(
  { firstname: "Stacey", lastname: "Starfish" },
  { id: lt(10) }
);

Delete records

Deletes can be executed via function delete at the table.

Deletes all records from table Person.

Person.delete();

Deletes only record with id 12 or nothing

Person.delete({ id: 12 });

Deletes all records with id greater 10 or nothing

Person.delete({ id: gt(10) });

Deletes all records with id greater 10 and lastname Starfish or nothing

Person.delete({ id: gt(10), lastname: "Starfish" });