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

crudplugin

v1.0.1

Published

Downloads

2

Readme

crudpluginModified

Rather than taking a mongodb collection as target, CRUD will take a mongoose model plus the JSON payload and will execute the desired action i.e. C, R, U or D...

This will free other services which leverage CRUD to define their data models and route handlers which will internally leverage CRUD functionality.

In summary, this plugging will be the main source or entry point of all CRUD requests?

To install the plugin into your project:

npm install crudplugin --save

To include it into your file

var crud = require('crudplugin');

For instance if you have a 'User' model, to create a new record for user, assuming the model has a field called 'email' that you want returned on successful creation: Method: create

 	crud.create(User, req.body.record)
    .then(record=>{
        return res.status(200).json(record.email);
    }).catch(err => {
        return res.status(500).json("A little error");
    })
	crud.deleteRecord(User, req.body.property, req.body.value)
	.then(user=> {
        if (user)
        {
            return res.status(200).json(user.username);
        }
        else {
            return res.status(500).json("some error");
        }

    }).catch(err => {
        return res.status(500).json("a little error");

    });

req.body.property is the field name and req.body.value is the value i the field you want a match to be deleted.

Take for instance this request structure:
   	{
 	   "property":"email",
       "value" : "[email protected]"
 	}

It would mean delete the record with email equals to [email protected]

Method: getRecordByProperty

Fetching a single record can come in handy with the following snippets:

	crud.getRecordByProperty(User, req.body.property, req.body.value)
    .then(user => {
        if (user) {
            console.log('Successfully retrieved user ' + user.email);
            return res.status(200).json(user);
        }
        else {
            console.log('Could not find user ');
            return res.status(200).json(false);
        }

    }).catch(err => {
        return res.status(500).json("a little error");
    });

req.body.property is the field name and req.body.value is the value i the field you want a match to be queried.

Take for instance this request structure:
   	{
 	   "property":"username",
       "value" : "daser"
 	}
 It would mean fetch the record with username equals to daser

Method: updateRecords This updates multiple fields in the model given some matching criteria.

 	crud.updateRecords(User, property, value, ["lastname","firstname"], ["kabam","Jurun"])
    .then(value => {
        return res.status(200).json(value);
    }).catch(err => {
        return res.status(500).json("a little error");

    });

property and value parameters works as previously seen, the third parameter is an array containing field names in the model with a corresponding values in the fourth parameter. Note that validation check is in place to ensure that their is a match otherwise an exception would be thrown.

Method: updateRecord This updates a single field in the model given some matching criteria.

	crud.updateRecord(User, property, value, "firstname", "Abiodun")
    .then(value => {
        return res.status(200).json(value);
    }).catch(err => {
        return res.status(500).json("a little error");

    });

property and value parameters works as previously seen, based on the matching criteria, we we changing "firstname" to "Abiodun".

Note the difference between: updateRecords and updateRecord (one is plural while the other is singular)