【发布时间】:2019-06-29 19:29:54
【问题描述】:
我要做的是通过在 Node.js 中使用 Sequelize ORM 来获取两个日期之间的行。我正在使用 PostgreSQL。问题是我提出的请求被 Sequelize 错误地解释了。
这是我用来发出请求的代码
const dbresp = await Table.findAll({
attributes: [...],
where: {
...
createdAt: {
$between: [new Date(Date(startDate)), new Date(Date(endDate))],
// same effect
// $lte: new Date(startDate),
// $gte: new Date(endDate),
},
},
logging: console.log,
raw: true,
order: [['createdAt', 'ASC']],
// limit: count,
});
通过记录原始 SQL 请求,很明显请求不正确
SELECT ...
FROM "table" AS "table"
WHERE "table"."createdAt" = '2019-02-05 21:00:00.000 +00:00'
"table"."createdAt" = '2019-02-05 21:00:00.000 +00:00'
ORDER BY "table"."createdAt" ASC;
提出此类请求的正确方法是什么?我应该使用原始查询吗?
我在谷歌上搜索过这个问题,但没有 StackOverflow 和 GitHub 提供帮助。
【问题讨论】:
标签: node.js postgresql orm sequelize.js