Reputation: 4517
My code is as shown below:
let time = db.Sequelize.DataTypes.NOW;
console.log('generated time is' + time);
db.js
const Sequelize = require('sequelize');
require('dotenv').config();
const db = {};
var sequelize = new Sequelize({
host: process.env.DB_HOST,
database: process.env.DB_NAME,
username: process.env.DB_USER_NAME,
password: process.env.DB_PASSWORD,
dialect: process.env.DB_TYPE,
port: process.env.DB_PORT,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
operatorsAliases: false
});
sequelize
.authenticate()
.then(() => {
console.log('connected to database successfully')
})
sequelize.sync({
force: false
})
db.Sequelize = Sequelize;
db.sequelize = sequelize;
The output that I get is
generated time is function NOW() {
if (!(this instanceof NOW)) return new NOW();
}
How can I generate timestamp with value ?
Upvotes: 0
Views: 1750
Reputation: 1
In Migration, you can use literal. This will help you, I also face such problem. This works:
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
Upvotes: -1
Reputation: 5233
That's absolutely the right way how it should work. Why do you think, it should return a timestamp? It should not. If you'd like to get a timestamp
, just run:
new Date().getTime()
Upvotes: 2