eggyal - - MySQL, , unix datetime/timestamp.
I found that a great way to achieve this is to use hooks inside sequelize. At the bottom of each of your models, you can add this code:
{
tableName: 'Addresses',
hooks : {
beforeCreate : (record, options) => {
record.dataValues.createdAt = Math.floor(Date.now() / 1000);
record.dataValues.updatedAt = Math.floor(Date.now() / 1000);
},
beforeUpdate : (record, options) => {
record.dataValues.updatedAt = Math.floor(Date.now() / 1000);
}
}
}
This inserts a field createdAtand updatedAtas a timestamp unix.
source
share