我的代码如下所示:
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;
我得到的输出是
generated time is function NOW() {
if (!(this instanceof NOW)) return new NOW();
}
如何生成带时间戳的值?
答案 0 :(得分:1)
这绝对是正确的方式。为什么你认为它应该返回一个时间戳?它不应该。如果您想获得timestamp
,请运行:
new Date().getTime()
答案 1 :(得分:-1)
在迁移中,可以使用文字。这将对您有帮助,我也面临此类问题。这有效:
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')