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

@beforesemicolon/node-json-db

v1.1.0

Published

A Simple file-based JSON database for Node

Downloads

37

Readme

Node JSON Database

A Simple file-based JSON database for Node

npm

Table of Contents

Install

npm i @beforesemicolon/node-json-db

Start a Database

To start simply initialize database with the name of the JSON file you want. All the files will be placed at the root of your project inside the .json-db-data directory.

import {JSONDB} from '@beforesemicolon/node-json-db';

type ToDoStatus = "pending" | "completed" | "archived"

interface ToDo {
  name: string;
  status: ToDoStatus;
  user: {
    name: string;
  };
}

const db = new JSONDB<ToDo>("todo");

CRUD

The database supports all the basic CRUD operations.

Insert Item

await db.insert({
  id: crypto.randomUUID(),
  name: "Go To Gym",
  status: "pending",
  user: {
    name: "John Doe",
  },
});

Get Item(s)

const item = await db.getOne()
  .where("status").equals("pending")
  .run();
const item = await db.getAll()
  .where("status").equals("pending")
  .where("user.name").equals("John Doe")
  .run();

Update Item(s)

const item = await db.updateOne({
    status: "completed"
  })
  .where("status").equals("pending")
  .run();
const item = await db.updateAll({
    status: "archived"
  })
  .where("status").equals("pending")
  .where("user.name").equals("John Doe")
  .run();

Delete Item(s)

const item = await db.deleteOne()
    .where("status").equals("pending")
    .run();
const item = await db.deleteAll()
    .where("status").equals("pending")
    .where("user.name").equals("John Doe")
    .run();

Drop Database

Simply drop the database to delete the JSON file.

db.drop()

Query API

The query helps you narrow down your search to identify the item or items you want to perform an action on.

// examples of values
import { VALUE } from "@typescript-eslint/scope-manager/dist/lib/base-config";

KEY_OR_KEY_CHAIN = "user" | "user.name" | "list.0.value" // use dot notation to navigate down
// db actions
ACTION = "getOne" | "getAll" | "updateOne" | "updateAll" | "deleteOne" | "deleteAll";
// value types
VALUE = "Any valid JSON value"

ACTION
  .where(KEY_OR_KEY_CHAIN).equals(VALUE)
  .where(KEY_OR_KEY_CHAIN).notEqual(VALUE)
  .where(KEY_OR_KEY_CHAIN).in(Array<VALUE>)
  .where(KEY_OR_KEY_CHAIN).between([MIN_VALUE, MAX_VALUE])
  .where(KEY_OR_KEY_CHAIN).greaterThen(VALUE)
  .where(KEY_OR_KEY_CHAIN).greaterOrEqual(VALUE)
  .where(KEY_OR_KEY_CHAIN).lessThen(VALUE)
  .where(KEY_OR_KEY_CHAIN).lessOrEqual(VALUE)
  .where(KEY_OR_KEY_CHAIN).matches(STRING_OR_REGEX)
  .where(KEY_OR_KEY_CHAIN).contains(VALUE)
  .where(KEY_OR_KEY_CHAIN).isNull()
  .where(KEY_OR_KEY_CHAIN).isNotNull()
  .where(KEY_OR_KEY_CHAIN).isTruthy()
  .where(KEY_OR_KEY_CHAIN).isFalsy()
  .where(KEY_OR_KEY_CHAIN).startsWith(STRING)
  .where(KEY_OR_KEY_CHAIN).endsWith(STRING)
  .where(KEY_OR_KEY_CHAIN).is((VALUE) => boolean)
  .run() // run the command