Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

customulize

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

customulize

Add arbitrary custom callbacks to sequelize

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
101
increased by3266.67%
Maintainers
2
Weekly downloads
 
Created
Source

customulize

Add arbitrary custom functions to sequelize models

Installation

npm install customulize

usage

var customulize = require('customulize');

var sequelizeCps = customulize('cps', function(model, method) {
    return function() {
        var newArgs = Array.prototype.slice.call(arguments),
            callback = newArgs.pop();
        model[method].apply(model, newArgs).complete(callback);
    };
});

// define your sequelize models
var models = {
    Account: require('./account')
};

// call function over them
sequelizeCps(models);

// now you can call methods via cps
models.Account.cps.find({ where: { id: 1} }, function(error, account) {
    if (error) {
        // error logic
    }
    account.name = 'John';
    account.cps.save(function(error, account) {

    });
});

kgo

customulize allows you to create a lazy calling pattern, eg:

var sequelazy = customulize('lazy', function(model, method) {
    return function() {
        var query = model[method].apply(model, arguments);
        return query.complete.bind(query);
    };
});

When using kgo this is especially convenient:

kgo
('account', Account.lazy.find({where: {id: 1}}))
('update', ['account'], function(account, done) {
    account.name = 'John';
    account.cps.save(done);
})
// etc, etc, etc

Pull requests welcome with passing tests.

Keywords

FAQs

Package last updated on 23 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc