const product = {
id: 1,
isAvailable: true,
lastUpdated: 4652082390 // epoch
};
await sequelize.query(`
UPDATE Product SET
isAvailable = $isAvailable,
lastUpdated = $lastUpdated
WHERE id = $id`,
{
bind: {
location: latlong,
isAvailable: isAvailable,
lastUpdated: lastUpdated,
id: product.id
}
}
);
它失败并出现错误:
SequelizeDatabaseError:参数'lastUpdated'的验证失败。值必须在-2147483648和2147483647之间。
似乎将lastUpdated值视为INTEGER,而不是BIGINT:(
我尝试了强制转换类型,如docs中所示:http://docs.sequelizejs.com/manual/raw-queries.html 但看起来此功能仅适用于Postgress,而不是我的情况
答案 0 :(得分:0)
await sequelize.query(`
UPDATE Product SET
isAvailable = $isAvailable,
lastUpdated = cast($lastUpdated as int)
WHERE id = $id`,
{
bind: {
location: latlong,
isAvailable: isAvailable,
lastUpdated: lastUpdated,
id: product.id
}
}
);
答案 1 :(得分:0)
BIGINT
是javascript的已知问题(没有真正的bigint)。
sequelize(以及与此相关的任何其他数据库npm)的解决方案是将BIGINT映射为字符串。
在您的情况下,我将尝试以下操作:
const product = {
id: 1,
isAvailable: true,
lastUpdated: '4652082390' // epoch
};