我有一个模型定义。 我想在该模型的postgres中进行高级选择查询。
原始查询看起来像这样:
SELECT 6371 * acos( cos( radians("+CustomerLat+") ) * cos(radians(sto.lat)) * cos( radians(sto.lng) - radians("+CustomerLng+") ) + sin( radians("+CustomerLat+") ) * sin(radians(sto.lat)) ) AS distance FROM stores sto ORDER BY distance ASC LIMIT 1我可以直接在模型上使用sequelize,而不是在原始中执行此操作吗?
Stores .findAll() .then(function(res){ //****// })I have a model defined. I would like to do an advanced select query in postgres on that model.
The raw query would look like this:
SELECT 6371 * acos( cos( radians("+CustomerLat+") ) * cos(radians(sto.lat)) * cos( radians(sto.lng) - radians("+CustomerLng+") ) + sin( radians("+CustomerLat+") ) * sin(radians(sto.lat)) ) AS distance FROM stores sto ORDER BY distance ASC LIMIT 1Could I do that with sequelize directly on the model without doing this in raw?
Stores .findAll() .then(function(res){ //****// })最满意答案
这个问题很老但是,我建议有两件事......首先,为什么你不使用PostGIS的postgresql扩展,这对于GIS数据来说是极好而快速的。 其次..不! 你不能这样做......但是对于高级where子句条件,我建议将其与Knex.js混合起来。 这是一个原始查询构建器。 您可以使用Knex.js构建where子句并将其与PostGIS混合以获得最佳结果。
This question is old but, There are two things I would suggest... Firstly why don't you use PostGIS a postgresql extension which is superb and fast when it comes to GIS data. Secondly.. No! you can't do that... But for advanced where clause conditions I would suggest mixing things up with Knex.js A raw query builder. You can use Knex.js to build your where clause and mix things up with PostGIS to get the best results.
更多推荐
发布评论