Last active
August 29, 2015 14:16
-
-
Save redroot/88ad587b7dd44238df5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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