作为原始条件的续集(Sequelize where condition as raw)

编程入门 行业动态 更新时间:2024-10-27 20:39:17
作为原始条件的续集(Sequelize where condition as raw)

我有一个模型定义。 我想在该模型的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 1

Could 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.

更多推荐

本文发布于:2023-07-07 04:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058919.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:续集   原始   条件   raw   Sequelize

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!