Skip to content

Instantly share code, notes, and snippets.

@budasuyasa
Created May 6, 2018 02:29
Show Gist options
  • Save budasuyasa/fa9800f79876e2cd7d8bd285ae0826f8 to your computer and use it in GitHub Desktop.
Save budasuyasa/fa9800f79876e2cd7d8bd285ae0826f8 to your computer and use it in GitHub Desktop.
medium-post-simple-rest-02
const book = sequelize.define('book', {
'id': {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
'isbn': Sequelize.STRING,
'name': Sequelize.STRING,
'year': Sequelize.STRING,
'author': Sequelize.STRING,
'description': Sequelize.TEXT,
'image': {
type: Sequelize.STRING,
//Set custom getter for book image using URL
get(){
const image = this.getDataValue('image');
return "/img/"+image;
}
},
'createdAt': {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW
},
'updatedAt': {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW
},
}, {
//prevent sequelize transform table name into plural
freezeTableName: true,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment