我正在尝试使用 sequelize 从 mysql 数据库中获取所有记录,并且尝试了以下方法:
shops.findAndCountAll({
where: {
createdAt: {
[Op.gte]: moment().subtract(7, 'days').toDate()
}
}
})
Run Code Online (Sandbox Code Playgroud)
当我使用它时,出现错误:
ReferenceError: moment is not defined
所以我尝试了这种方法:
shops.findAndCountAll({
where: {
createdAt: {
[Op.gte]: Sequelize.literal('NOW() - INTERVAL "7d"'),
}
}
})
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '42000',
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near '' at line 1",
sql: "SELECT count(*) AS `count` FROM `shop` …Run Code Online (Sandbox Code Playgroud)