Select Bookshelf MySQL、Knex 在 node.js 的两个日期之间创建的对象

Select object created between two dates by Bookshelf, MySQL, Knex on node.js

我需要获取两次之间创建的对象的列表;

我可以通过编写 SQL 查询来获取数据;

但我需要通过 Bookshelf 编写此查询;

我的简单查询:

    router.route('/locations')
  // fetch all locations
  .get(function (req, res) {
    Locations.forge()
    .fetch()
    .then(function (collection) {
      res.json({error: false, data: collection.toJSON()});
    })
    .catch(function (err) {
      res.status(500).json({error: true, data: {message: err.message}});
    });
  })

如何像上面的查询那样获取两个日期之间的位置?

尝试向链中添加一个 query() 调用,例如

Locations
  .forge()
  .query(function(qb) {
    qb.whereBetween('creation', [initialDate, finalDate]);
  })
  .fetch()
  .then(function (collection) {
    res.json({error: false, data: collection.toJSON()});
  })
  .catch(function (err) {
    res.status(500).json({error: true, data: {message: err.message}});
  });

查看书架 Collection.query() and Knex Query Builder and whereBetween()