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

crudpluginobject

v1.0.2

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?

A good example is USER... this defines 'user' data model with various fields to differntiate between the various types of users (normal, admin, superuser) ..., Take note that USER would also handle the dbase connection.

So USER leverages CRUD by 'importing' it via NPM.

Next it passes the dbase connection and required model into the CRUD 'constructor'.. Then the route handlers would intercept the requests and call the functionality exposed by CRUD

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 crudpluginobject --save

To include it into your file

var crudplugin = require('crudpluginobject').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:

crud.create(req.body.record)
.then(record=>{
   return res.status(200).json(record.email);
}).catch(err => {
  return res.status(500).json("A little error");
})
	crud.deleteRecord(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(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(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(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)