我需要获取两次之间创建的对象的列表;
我能够通过编写 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}});
});
查看书架集合.query() http://bookshelfjs.org/#Collection-instance-query和克内克斯查询生成器 http://knexjs.org/#Builder and whereBetween() http://knexjs.org/#Builder-whereBetween
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)