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 🙏

© 2026 – Pkg Stats / Ryan Hefner

small-db

v1.1.1

Published

It's a lightweight, local db, suitable for small datasets.

Readme

Small-db

Small-db is a database useful when you would have to keep small information persistent on the server.

Installing

	npm install small-db

Use-cases

A good example would be a news section on a basic website. Using this module you could easily add, remove, modify and show the information without really worrying about running out of space or the program slowing down.# How it works

How it works

The databased is loaded on RAM and after the necessary operations have been made, it can be stored on disk with the commit() method. This makes it fast but it’s impractical to handle big data with it. All the information is saved in a JSON file which has its limitations.

Terminology

There are collections which have documents in them. The collection is a way to group your documents, it can be seen as an RDBS table. Each document has a unique id that can be used to reference it.# Guide

Importing the Database

	const  DataBase = require('small-db');

Creating or opening a collection

	let  clientsColection = new DataBase().collection('clients.json');

Seeing the documents (returns the map of the documents)

	clientsColection.documents;

Adding a document (returns the id of the document created)

	let id = clientsColection.addDocument({a : "b"});

Removing a document (return true if the document could be removed)

	clientsColection.removeDocument(id);

Checking if the id exist

	clientsColection.has(id);

Updating a document (if the id doesn't exist it creates one)

	clientsColection.updateDocument(id,{ c : "d"});
	

Writing the collection on the disk

	clientsColection.commit();
		

Querying "." is reserved for traversing the json object

	clientsColection.addDocument({a :{b : "c"}});
	clientsColection.where("a.b == c");	

Where function ( returns a query object)

	clientsColection.where("name == George").where("age > 25");
	clientsColection.where("number.mobile == 000");

Remove documents

	clientsColection.where("age >=50").remove();

Update documents

	clientsColection.where("age > 18").update("prefix",(data)=>{
		if(data["sex"]="M")
			return "Mr";
		return "Mrs";
	});

Sorting the documents

	clientsColection.where("salary < 500").sortBy('age');
	// or if we want to specify the direction (by default is 'asc')
	clientsColection.where("salary < 500").sortBy('age','desc');

Getting the first documents with limit method

	clientsColection.where("age > 18").limit(10);	

Getting the number of clients that are underaged

	clientsColection.where("age < 18").size;

Values method returnes the documents values as an array

	for(val of clientsColection.values){ 
		console.log(val) 
		}

Keys returnes the documents keys

	for(val of clientsColection.keys){
		 console.log(val) 
	 }

Usage

npm install small-db

Each collection function generates or works with an unique id, addDocument returns and id, removeDocument and updateDocument takes in an id. When working with a query the id is not needed.

A simple example showing a tipical usecase for populating and interogating the database.

let  clientsColection = new DataBase().collection('clients.json');

clientsColection.addDocument({ "first-name":  "Jhon",
								"last-name" :  "Lake",
								age :  "18",
								contacts : { mobilePhone :  12345,
								homePhone :  23456
							} });
clientsColection.addDocument({ "first-name":  "Kayle",
								"last-name" :  "Martin",
								age :  "25",
								contacts : { mobilePhone :  98765,
								homePhone :  87654
							} });
clientsColection.addDocument({ "first-name":  "Don",
								"last-name" :  "Dibble",
								age :  "30",
								contacts : { mobilePhone :  99999,
								homePhone :  89999
							} });

/* The first where statment would have returned 2 results, but
because we further searched for a specific mobile number, only the
last object remains, so the update changes the last object first
name from Don to Ned. */
clientsColection.where("age > 20")
				.where("contacts.mobilePhone == 99999")
				.update("first-name", (obj) => {return  "Ned";});

//Displaying all the collection documents
for(val  of  clientsColection.values){
	console.log(val)
}

//Displaying information based on query
for(val  of  clientsColection.where("age > 0").sortBy("age").values){
	console.log(val);
}

//This removes documents form a collection based on a query
clientsColection.where("first-name == Jhon").remove();

 
//But we can remove the keys directly from the collection if we want to
for(key  of  clientsColection.where("first-name == Kayle").keys){
	clientsColection.removeDocument(key);
}

clientsColection.commit();