[英]Using a datetime function on a column using Sequelize
I'm trying to calculate the difference (in seconds) between CURRENT_TIMESTAMP
and a DATETIME column. 我正在尝试计算
CURRENT_TIMESTAMP
和DATETIME列之间的差异(以秒为单位)。 I've just used TIMESTAMPDIFF(SECOND, CURRENT_TIMESTAMP, someColumnName)
in SQL, but I am having trouble doing this using Sequelize. 我刚刚在SQL中使用了
TIMESTAMPDIFF(SECOND, CURRENT_TIMESTAMP, someColumnName)
,但是使用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将函数用作属性?
使用sequelize.col标记该列(否则它将作为字符串转义)
sequelize.fn('TIMESTAMPDIFF', 'SECOND', 'CURRENT_TIMESTAMP', sequelize.col('createdAt'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.