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

redis-crud

v0.1.1

Published

A simple library for CRUD functionalities using REDIS

Downloads

2

Readme

redis-crud

A very simple library for generating models that uses REDIS as the database and provides the basic CRUD functionality.

Usage

const redis = require('then-redis');
const db = redis.createClient();
const generateModel = require('redis-crud').generateModel;

const UserModel = generateModel('User');

// Insert a new record and get the serial id using promise
UserModel.insert({username: 'admin', password: 'pwd'}).then(id => {
  console.log('New record id is ', id);
});

// Retrieve the record
UserModel.get(1).then(obj => {
  console.log('The record at 1 is ', obj);
});

// Update the record
UserModel.update(1, { name: 'John Doe' }).then(() => {
  // The record is updated
});

// Delete the record
UserModel.delete(1).then(res => {
  // The record is deleted
});

// Iterate through all the records, providing the number of records to
// retrieve on each iteration
const iterator = UserModel.iterate(10);
iterator.next().then(records => {
  // The list of records are available here
});

Using hooks

const UserModel = require('redis-crud').generatorModel(db, 'User');

// The hook invoked before a new record is inserted, with the object instance
// that is being inserted. Throw an error here to avoid the record from
// being inserted
UserModel.beforeInsert = function(obj) {

};

// The hook invoked after the record is inserted. The hook is provided with
// the new id of the record. Do the post record insertion operations here,
// like create secondary records for easy data retrieval based on certain
// properties
UserModel.afterInsert = function(obj, id) {

};

// The hook invoked before the record is updated. The obj provides the
// properties that are going to be updated (either new or old). Throwing an
// exception here will stop the record from being updated
UserModel.beforeUpdate = function(id, obj) {

};

// The hook invoked after the record is updated. The parameters are same as
// the ones provided in beforeUpdate
UserModel.afterUpdate = function(id, obj) {

};

// The hook invoked before the record is deleted. The obj provides the object
// in the database that is going to be removed. Throwing an exception here will
// stop the record from being deleted
UserModel.beforeDelete = function(id, obj) {

};

// The hook invoked after the record is deleted.
UserModel.afterDelete = function(id, obj) {

};