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

simple-node-jsondbv2

v1.0.4

Published

A very easy to use jsonDB for small projects/ Testing.

Downloads

1

Readme

simple-node-jsondbv2

Extremely lightweight and simple local json database for personal / small / test projects.

Version 2 of simple-node-jsondb

Installation

npm i simple-node-jsondbv2

Usage

const db = require('simple-node-jsondbv2');

or

import { dbInsert, dbUpdate } from 'simple-node-jsondbv2';

Features

  • + Extremely lightweight
  • + Very simple to use
  • + Syntax similar to mongoose
  • + Capable of find, insert, update, delete
  • - Targeting deep Object does not work. You need to manipulate the data manually and save it as whole.
  • - Indexing not supported yet, thus not recommended for large scale production use. Use a proper DB for that.

Table Of Contents

  • dbInit()
  • dbInsert()
    • Insert one
    • Insert many
  • dbFind()
    • Find All
    • Multiple filters
    • Advance Search
  • dbFindOne()
  • dbUpdate()
    • Update All records
    • Update One
    • New record
  • dbDelete()
    • Delete one specific record
    • Delete records with conditions
  • Special Operators

dbInit(dbPath: string)

To use the db, you need to initialize the db folder onload before you can use it, Simply pass in the desired absolute path to change the directory. Path should be absolute

const path = require("path")
const dbPath = path.join(__dirname, '<your-path-folder>') 
dbInit(dbPath)

This will create a "db" folder on that path, all the data will be stored in the "db" folder.

dbInsert(collection: string, data: object[] | object)

  • Insert data into database.
  • Refer as "collection" for noSQL users, or "table" for users that is more fimilar with SQL.
  • New object id will be injected as "_id" for each document.

| Params | Required | Type | Description | | ---- | ---- | ---- | ---- | | collection | True | String | Target collection/table | | data | True | Object/Object[] | Data to insert into collection/table. Can be either Object or Array. |

Return

  • None

Example

Insert one

const fruit = {
    name: "Apple",
    price: 15
}
// New collection "fruits" will be created automatically.
await dbInsert( 'fruits', fruit );

Insert many

By using Array

const fruitList = [
    { name: "Apple", price: 15 },
    { name: "Orange", price: 30 },
]
await dbInsert( 'fruits', fruitList );

dbFind(collection: string, filter: object)

  • Find and retrieve data from database

| Params | Required | Type | Description | | ---- | ---- | ---- | ---- | | collection | True | String | Target collection/table | | filter | True | Object | Filter. Pass an empty Object to find all |

Return

  • Array

Example

Find All

const results = await dbFind( 'fruits' , {});

Multiple filters

const results = await dbFind( 'fruits' , {name: "Apple", price: 15});

Advance filters

Advanced search with filtering can be done by using Special Operators. Check out Special Operators section in the end of the page for more info.

const results = await dbFind('fruits',{
    name: "Apple",
    price: { $lte: 10 }
});

dbFindOne(collection: string, filter: object)

  • Find and retrieve data from database

| Params | Required | Type | Description | | ---- | ---- | ---- | ---- | | collection | True | String | Target collection/table | | filter | True | Object | Filter. Pass an empty Object to find all |

Return

  • Object

dbUpdate(collection: string, filter: object, data: object, newDoc: boolean[false])

  • Update all the document that matches the filter.

| Params | Required | Type | Description | | ---- | ---- | ---- | ---- | | collection/ | True | String | Target collection/table | | filter | True | Object/Array | Filter. Can be either Object or Array. | | newData | True | Object/Array | New data to overwrite. Can be either Object or Array. | | newDoc | False | BOolean | If enabled, it will create a new record is non are found |

Return

{ 
    modified: number,
    new: number 
}

Example

Update All records

const stats = dbUpdate("fruits", {}, { price: 10 })

Update One

const stats = dbUpdate("fruits", {name: "Apple"}, { price: 10 })

dbDelete(collection: string, filter: object)

  • Delete document that matches the filter.

| Params | Required | Type | Description | | ---- | ---- | ---- | ---- | | collection | True | String | Target collection | | filter | True | Object/Array | Filter. Can be either Object or Array. |

Return

{ 
    deleted: number
}

Example

Delete one specific record

const deleted = await dbDelete("fruits", { name: "Apple" })

Delete records with conditions

const deleted = await dbDelete("fruits", { 
    price: { $gte: 10, $lt:20 }
})

Special Operators

Operators | Descriptions ------------- | ------------- $gte | Greater and equals to $gt | Greater than $lte | Lesser and equals to $lt | Lesser than