Skip to content

Instantly share code, notes, and snippets.

@andrewjmead
Created November 27, 2015 20:07
Show Gist options
  • Save andrewjmead/c8bd6bea9a74e9ec2ac9 to your computer and use it in GitHub Desktop.
Save andrewjmead/c8bd6bea9a74e9ec2ac9 to your computer and use it in GitHub Desktop.
Custom Sequelize Validation
module.exports = function(sequelize, DataTypes) {
return sequelize.define('todo', {
description: {
type: DataTypes.STRING,
allowNull: false,
validate: {
len: [1, 250]
}
},
completed: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
validate: {
isBoolean: function (value) {
if (typeof value !== 'boolean') {
throw new Error('Completed must be a boolean');
}
}
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment