使用 mysql 函数执行查询,例如 bookshelf.js 中的 now()

perform a query with mysql function like now() in bookshelf.js

在 Knex.js/bookshelf.js 中,我如何执行以下操作

select * from `events` where end_time >= now() 

现在在 where() 中传递会导致它被当作参数而不是函数

 qb.andWhere("end_time", ">=", "now()");

在书架上不确定,但直接使用Knex,我想你应该试试:

qb.andWhere("end_time", ">=", knex.fn.now());

关键是使用原始查询。 Knex 带有使用原始查询的选项。这将阻止 now() 成为查询

的参数(即?)
MyModel.forge()
     .query(function(qb) {
        qb.whereRaw("end_time >= now()")
     })