Skip to content

Instantly share code, notes, and snippets.

@krupalimakadiya
Created April 10, 2021 01:31
Show Gist options
  • Save krupalimakadiya/2d4629cc39349cd11ad7947f8ecf245f to your computer and use it in GitHub Desktop.
Save krupalimakadiya/2d4629cc39349cd11ad7947f8ecf245f to your computer and use it in GitHub Desktop.
Sequelize virtual field or virtual column.
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