Created
May 6, 2018 02:29
-
-
Save budasuyasa/fa9800f79876e2cd7d8bd285ae0826f8 to your computer and use it in GitHub Desktop.
medium-post-simple-rest-02
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
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