I'm trying to calculate the difference (in seconds) between CURRENT_TIMESTAMP
and a DATETIME column. I've just used TIMESTAMPDIFF(SECOND, CURRENT_TIMESTAMP, someColumnName)
in SQL, but I am having trouble doing this using Sequelize.
I've tried doing something like this, but I can't seem to get the syntax right:
Project
.findAll({
include: [Note, Link],
attributes: [
[sequelize.fn('TIMESTAMPDIFF', 'SECOND', 'CURRENT_TIMESTAMP', 'createdAt'), 'diff']
]
})
.then(res.send.bind(res));
Is there a way of adding using a function as an attribute using Sequelize?
使用sequelize.col标记该列(否则它将作为字符串转义)
sequelize.fn('TIMESTAMPDIFF', 'SECOND', 'CURRENT_TIMESTAMP', sequelize.col('createdAt'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.