Created
April 10, 2021 01:31
-
-
Save krupalimakadiya/2d4629cc39349cd11ad7947f8ecf245f to your computer and use it in GitHub Desktop.
Sequelize virtual field or virtual column.
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
module.exports = (sequelize, DataTypes) => { | |
return sequelize.define('users', { | |
id: { | |
autoIncrement: true, | |
type: DataTypes.INTEGER(5), | |
allowNull: false, | |
primaryKey: true | |
}, | |
firstname: { | |
type: DataTypes.STRING(50), | |
allowNull: true | |
}, | |
lastname: { | |
type: DataTypes.STRING(50), | |
allowNull: true | |
}, | |
email: { | |
type: DataTypes.STRING(50), | |
allowNull: true | |
}, | |
profileImg: { | |
type: DataTypes.STRING(100), | |
allowNull: true, | |
}, | |
imageUrl: { | |
type: DataTypes.VIRTUAL, | |
get() { | |
return this.profileImgPath ? `localhost:8000/images/${this.profileImg}` : null; | |
}, | |
} | |
}, { | |
sequelize, | |
tableName: 'users', | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment