Skip to content

Instantly share code, notes, and snippets.

@redroot
Last active August 29, 2015 14:16
Show Gist options
  • Save redroot/88ad587b7dd44238df5a to your computer and use it in GitHub Desktop.
Save redroot/88ad587b7dd44238df5a to your computer and use it in GitHub Desktop.
//e.g.
var _ = require('underscore');
var common_model_extensions = require('lib/util/model_extensions').common;
// which would be:
module.exports = {
common: {
classMethods: {
updateById: function(id, data, cb){
logger.debug("Updating record with id", id);
this.update(data, { where: { id: id } }).then(cb);
},
deleteById: function(id, cb){
logger.debug("Deleting record with id", id);
this.destroy(data, { where: { id: id } }).then(cb);
}
}
}
}
// then define the model
var Metric = sequelize.define('metrics',{
date: Sequelize.STRING,
group: Sequelize.STRING,
key: Sequelize.STRING,
value: Sequelize.FLOAT
}, {
timestamps: false,
classMethods: _.extend(common_model_extensions,{
customMethod: function(){
}
})
});
// then you can call Metric.updateById, essential were are extending Sequalize models rather than adding another layer in front of them
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment