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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sqlite-json-db

v0.0.8

Published

sqlite-json-db is an embedded json database (backed by sqlite) with a mongo inspired minimal query api, and firebase style realtime subscriptions.

Readme

sqlite-json-db

sqlite-json-db is an embedded json database (backed by sqlite) with a mongo inspired minimal query api, and firebase style realtime subscriptions.

Status:

:warning: Beta (Some APIs subject to change)

Installation:

For node.js:

npm install better-sqlite3 sqlite-json-db

For bun:

npm install sqlite-json-db # Works with bun's native sqlite driver

Usage

Import the right adapter for your environment

// One of:
import Database from "sqlite-json-db/better-sqlite3"; // For node.js
import Database from "sqlite-json-db/bun-sqlite"; // For bun

Initialize db

// Uses in-memory database
const db = new Database();

// Pass a file path for a persisted databaes:
const db = new Database("data/sqlite.db");

Create Collections and Set Documents

Collections are created on first insertion of a document.

// Define an interface for the type of record - this must be JSON compatible.
interface User {
    name: string
    age: number
}

// Now we can define a collection
const users = db.collection<User>("users");
// users is the name of the underlying sqlite table
// which will be created on first access

// We can now create refs to documents
const usersRef = users.doc("1"); // Id is optional - if omitted, random uuid will be used

await usersRef.put({
  name: "John Doe",
  age: 100
});
// Saves the document to db

Get a particular document

// define ref
const usersRef = db.collection<User>("users").doc("1");
// get
const user = await usersRef.get();
// print
console.log(user); // prints { name: "John Doe", age: 100 };

Update Documents in Collections

// ref
const usersRef = db.collection<User>("users").doc("123");

// Insert/Replace the complete document
await ref.put({ name: "DERP Doe", age: 100 });
// document in DB is now { name: "DERP Doe", age: 100 }

// Selectively update specific properties
await ref.update({ name: "DERP Doe" });
// document in DB is now { name: "DERP Doe" }
// This will not do anything if the doc is not already present

Delete Documents in Collection

const db = new Database();

const ref = db.collection("users").doc("deletable");

await ref.put({ username: "deletableUsername", updatedAt: 123123 });

await ref.delete();

const doc = await ref.get();

console.log(doc); // prints null

Listen to real-time updates of documents.

// ref to doc
const ref = db.collection("users").doc("123");

// snapshot listener returns unsubscribe function
const unsub = ref.onSnapshot((doc) => {
  console.log("Omg the user doc is updating!", doc?.username);
});

await ref.put({ username: "SHEESH Doe", updatedAt: 2 });
// prints: `Omg the user doc is updating! SHEESH Doe`

// unsub
unsub();

Query Documents in a collection by equality comparison

const usersRef = db.collection("users");

await usersRef.doc().put({
    username: "zareith",
    updatedAt: 234
});

const query = usersRef.where({
    username: {
        $eq: "zareith"
    }
});

const docs = await query.get();

const user = docs[0];

console.log(user.username); // prints `zareith`

Besides $eq for equality, we can use $gt, $gte, $lt, $lte:

usersRef.where({
    username: {
        $eq: "zareith",
    },
    updatedAt: {
        $gt: 200
    }
}).get();

// Finds all documents where username == "zareith" and updatedAt > 200

Complex conditions are possible through $and and $or:

usersRef.where({
    $or: [
        { username: { $eq: "zareith" } },
        { updatedAt: { $gt: 200 } },
    ]
}).get();

// Finds all documents where username == "zareith" OR updatedAt > 200

For the common case of find by exact match, whereEq is available as a convenience:

usersRef.whereEq({ username: "zareith" }).get();

Equivalent to:

usersRef.where({ username: { $eq: "zareith" }}).get();

License

MIT

Credits/Inspirations

This library is heavily inspired by doculite by Stefan Bielmeier, and the initial test suite and API structure were borrowed from there.