将 SQL 转换为 KNEX 多个条件

converting SQL into KNEX multiple conditions

我正在尝试将我的 SQL 转换成 KNEX。我到目前为止是:

SQL:

SELECT name from students where attendance = "90" AND timestamp between "2020-05-14" AND "2020-05-18";

我尝试转换为 KNEX:

const from = req.query.from;
const to = req.query.to

router.get('/students/attendance?from=&to='

req.db.from('students').select("*").where('attendance', '=', req.params.attendance).andWhere('timestamp', 'between', [from, to])

MYSQL 代码有效,returns 我想要什么,但我假设 Knex 的语法有误。请往正确的方向推

此处记录了 between 的位置 https://knexjs.org/#Builder-whereBetween

await req.db
  .from('students')
  .select("*")
  .where('attendance', req.params.attendance)
  .whereBetween('timestamp', [from, to])

您也可以使用 .toSQL() 检查构建的查询查询。