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

oxzof-nosql

v1.0.2

Published

A lightweight NoSQL-style database built on SQLite. Stores JSON data with auto-increment _id and supports MongoDB-like operations (insertOne, find, findOne). Ideal for simple, file-based NoSQL solutions.

Downloads

179

Readme

NoSQL Database with SQLite (Custom Implementation)

This project provides a simple NoSQL-style database using SQLite. Similar to MongoDB, data is stored in JSON format, and each entry is assigned a unique _id. The database supports fundamental MongoDB-like operations such as insertOne, find, findOne, and createCollection.

Table of Contents

Installation

  1. Install Node.js
    Ensure you have Node.js installed on your system.

  2. Install Dependencies
    Run the following command in your project's root directory:

    npm install

    This will install all required dependencies, including SQLite3 and UUID.

Usage

Database Connection

To establish a connection to the database:

const NoSQLDB = require("oxzof-nosql");
const db = new NoSQLDB();

Once connected, you will see the message: Database connected.

Creating a Collection

To create a new collection:

await db.createCollection("users");

If the collection already exists, it will not be recreated.

Inserting Data (insertOne)

To insert a new document:

await db.insertOne("users", { name: "John", age: 25, gender: "M" });

This operation automatically assigns a unique _id and stores the data in the collection.

Querying Data (find and findOne)

  • Retrieve all documents:
const users = await db.find("users");
console.log(users); // Lists all users
  • Find a specific document:
const user = await db.findOne("users", { name: "John" });
console.log(user); // Returns the first matching document

find returns an array of all matching documents, while findOne returns only the first match.

Closing the Database (close)

To close the database connection:

db.close();

This function terminates the database connection and stops the application.

API Functions

createCollection(name)

Creates a new collection.

  • Parameters:

    • name (String): The name of the collection.
  • Example:

    await db.createCollection("users");

insertOne(collection, data)

Inserts a document with a unique _id and stores it in JSON format.

  • Parameters:

    • collection (String): The collection name.
    • data (Object): The document to be inserted.
  • Example:

    await db.insertOne("users", { name: "John", age: 25, gender: "M" });
  • Return Value: { _id, ...data }: Returns the inserted document.

find(collection, filter)

Finds all documents in a collection. Filtering is optional.

  • Parameters:

    • collection (String): The collection name.
    • filter (Object): The search criteria.
  • Example:

    const users = await db.find("users", { name: "John" });
    console.log(users);
  • Return Value: Array: Returns an array of matching documents.

findOne(collection, filter)

Finds the first document that matches the filter criteria.

  • Parameters:

    • collection (String): The collection name.
    • filter (Object): The search criteria.
  • Example:

    const user = await db.findOne("users", { name: "John" });
    console.log(user);
  • Return Value: Object: Returns the first matching document.

close()

Closes the database connection.

  • Example:
    db.close();

Testing

Below is a sample index.js file to test the project:

const NoSQLDB = require("oxzof-nosql");
const db = new NoSQLDB();

async function main() {
    console.log(await db.createCollection("users"));

    // Each inserted document will have a unique _id
    console.log(await db.insertOne("users", { name: "John", age: 25, gender: "M" }));
    console.log(await db.insertOne("users", { name: "Mike", age: 30, gender: "M" }));
    console.log(await db.insertOne("users", { name: "Anna", age: 22, gender: "F" }));

    console.log("All users:", await db.find("users"));
    console.log("Find John:", await db.findOne("users", { name: "John" }));

    db.close();
}

main();

About the Project

This project provides a NoSQL-style database architecture on top of SQLite. It is ideal for those who need the flexibility of NoSQL databases like MongoDB while leveraging the simplicity of a file-based SQLite storage system. Each inserted document is assigned a unique _id and is stored in JSON format.