我想做的是使用 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 都没有提供帮助。