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

suyotechdb

v0.0.7

Published

JSON File Based Database Inspired by Mongoose ODM

Downloads

17

Readme

suyotechdb - File-based JSON Database Inspired by Mongoose ODM with Zero Dependency

This repository provides a lightweight, file-based JSON database system inspired by Mongoose ODM. It allows you to model, store, and retrieve data using a schema-based approach similar to Mongoose, but all data is stored in local JSON files.

Developed by - suyotech.com

Table Of Contents

Features

  • Zero Dependency
  • Schema-based data modeling
  • Simple CRUD operations
  • Validation and default values
  • File-based storage for easy setup and portability
  • All functions are syncronous. (Async not supported for easy usage)

Installation

To install the required dependencies, run:

npm install suyotechdb

Usage

CJS

const { Schema, Model } = require('suyotechdb');

const userSchema = new Schema({
  name: { type: String, required: true,default : "" },
  email: { type: String, required: true, default: "" },
  age: { type: Number, default: 18 },
});

// define database path where to save files
const database_path  = "./db"; 

const User =  new Model('users',database_path, userSchema);

ESM

import { Schema, Model } from 'suyotechdb' ;

const userSchema = new Schema({
  name: { type: String, required: true,default : "" },
  email: { type: String, required: true, default: "" },
  age: { type: Number, default: 18 },
});

//define database path where to save files
const database_path  = "./db"

const userModel =  new Model('users',databse_path, userSchema);

CRUD Operations

createOne

Use the createOne function to add a new item


userModel.createOne({
  name : "suyog",
  email : "[email protected]",
  age : 20,
})

insertMany

Use the insertMany function to add a new item


const users = [
{
  name : "suyog",
  email : "[email protected]",
  age : 20,
},
{
    name : "user2",
  email : "[email protected]",
  age : 26,
}
]

userModel.insertMany(users)

findOne

Use the findOne function to find one document

const user = userModel.findOne({name : "suyog"})
console.log(user); // { id: ksldf09-ksdjflsd-sdkfsld, name: 'suyog',email : "[email protected]",age : 20 } 

findAndDeleteOne

Use the findAndDeleteOne to find first matching document and delelte.

const query = {name : "suyog"}
const result = userModel.findAndDeleteOne(query)
console.log(result) // deleted successfully

findOneAndUpdate

Use the findOneAndUpdate to find first matching docuemnt and update.

const query = {name : "suyog"}
cosnt updateData = {age : 30}
const result = userModel.findAndDeleteOne(query,updateData)
console.log(result) // updated successully

udpateMany

Use the udpateMany to find first matching docuemnt and update.

const query = {name : "suyog"}
cosnt updateData = {age : 30}
const result = userModel.updateMany(query,updateData)
console.log(result) // updated successully

deleteMany

Use the deleteMany to find first matching docuemnt and update.

const query = {name : "suyog"};
const result = userModel.deleteMany(query);
console.log(result) // updated successully

find

This is special query which can use many different chained operations

  • It supports following operation for query operators
    • $in - Finds value in field
    • $nin - Check not in values
    • $eq - Equals to
    • $ne - Not equals to
    • $gte - Greater Than
    • $lte - Less Than
  • Chained Functions
    • sort - Sort by given query
    • limit - Limits Documents
    • skip - Skips Documents
    • select - Select or deselect based value 0 or 1 respectively
    • distinct - Distinct Field Values
    • count - Count of find query result
    • exec - Function need after find or chained to return data.
const query  = {age  :{$gte: 10}}
const result = userModel
          .find(query)
          .sort({name : 1})
          .limit(5)
          .skip(2)
          .select({name : 1})
          .exec()