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

@mattellis91/mockdb

v0.0.5

Published

Simple database system for handling mock data.

Downloads

2

Readme

Mockdb

Create and manage mock document orientated databases using mongodb like filters.

Install

npm i @mattellis91/mockdb

Database

Create a new database , connect to an existing database or remove an existing database with the MockDb static methods

Databases are represented as subdirectories of the root MockDb directory that is created when creating the 1st database for the project.

project
│       
└─── mockdb
│    └─── testdb
│    └─── testdb2
import { MockDb } from '@mattellis91/mockdb';

//connect to an existing database. If the database does not exist. 
//It will be created and a connection to it will be returned
const connection = MockDb.connect('testDb');

//create new db without connecting
//const connection = MockDb.createDb('testDb');

//remove an existing db
//await MockDb.removeDb('existingDb')

Collections

Manage collections of documents. Collections are represented as json files inside the relevant database subdirectory.

project
│       
└─── mockdb
│    └─── testdb
│    │    └─── testCollection.json
│    └─── testdb2
//get reference to an existing collection or create a new one if the collection doesn't exist
const collection = connection.collection('testCollection');
    
//use collection the reference to peform operations on the collection

//insert documents into the collection. If an id isn't provided a random one will be generated.
collection.insertOne({ _id: cjld2cjxh0000qzrmn831i7rn, foo: 1, bar: false });
collection.inserMany([
    {
        foo: 2,
        bar: true
    },
    {
        foo: 3,
        bar: false
    },
    {
        foo: 4,
        bar: true
    },
]);

//retrieve all documents in the collection
collection.find();

//retrieve a single document by Id
collection.findById('cjld2cjxh0000qzrmn831i7rn');

//remove a single document by Id
collection.removeById('cjld2cjxh0000qzrmn831i7rn');

//remove all documents that match filter
collection.remove({bar: false});

//get number of documents in the collection
collection.count();

//remove collection from database
connection.dropCollection('testCollection');

Filter

Filter documents using mongodb like query operators


//find all documents that match filter
collection.find({ foo: {$gt: 2} });

//find first document that matches filter
collection.findOne({ foo: {$gt: 2} })

//filter documents using logical operators
collection.find(
    {
        $or: [
            { foo: {$lt: 2} },
            { bar: true }
        ]
    }
)

const collection.find({
            $and: [
                { bar: true },
                { $or: [{ foo: 1}, {foo: {$ne: 4}, bar: {$exists: true}} ]}
            ],
        });
        
        
//remove all documents that match filter
collection.remove({bar: true});

//remove first document that matches filter
collection.removeOne({bar: false});

Current supported filter operators

| Operator | Description | | ------------- |------------- | | $eq | Matches values that are equal to a specified value.| | $ne | Matches all values that are not equal to a specified value. | | $gt | Matches values that are greater than a specified value. | | $gte | Matches values that are greater than or equal to a specified value. | | $lt |Matches values that are less than a specified value. | | $lte | Matches values that are less than or equal to a specified value. | | $lte | Matches values that are less than or equal to a specified value. | | $in | Matches any of the values specified in an array. | | $nin | Matches none of the values specified in an array. | | $exists | Matches documents that have the specified field. | | $text | Performs text search. | | $and |Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. | | $or | Joins query clauses with a logical OR returns all documents that match the conditions of either clause. |

Update

Update documents using mongodb like update operators

//update all documents that matches filter
collection.update({foo: {$gt: 2} }, {$set : {bar : false } });

//update first document that matches filter
collection.updateOne({foo: {$lt: 2} }, {$set : {bar : true } });

//update document by Id
collection.updateById('cjld2cjxh0000qzrmn831i7rn', {$set : {foo : 100 } });

//upsert document by adding setting upsert property to true on update filter
collection.updateOne({foo: {$gt: 1000} }, {$set : {bar : true }, upsert: true });

Current supported update operators

| Operator | Description | | ------------- |------------- | |$set | Sets the value of a field in a document.| | $inc | Increments the value of the field by the specified amount. | | $mul | Multiplies the value of the field by the specified amount. | | $min | Only updates the field if the specified value is less than the existing field value. | | $max | Only updates the field if the specified value is greater than the existing field value. | | $unset | Removes the specified field from a document. | | $rename | Renames a field. | | $setOnInsert | Sets the value of a field if an update results in an insert of a document. Has no effect on update operations that modify existing documents. | | $addToset | Adds elements to an array only if they do not already exist in the set. | | $pop | Removes the first or last item of an array. | | $push | Adds an item to an array. | | $pullAll | Removes all matching values from an array. |

Roadmap

  • Add exporting / importing data from databases
  • Add additional filter operators
  • Add add update operators
  • Add random data generation

Tests

npm run test

Contact

Created by Matt Ellis. Feel free to contact me

License

This project is open source and available under the MIT License.