Sequelize where 条件为原始

Sequelize where condition as raw

我定义了一个模型。我想在该模型的 postgres 中进行高级 select 查询。

原始查询如下所示:

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 来做到这一点,而无需在 raw 中这样做吗?

Stores
.findAll()
.then(function(res){ //****// })

这个问题很老但是,我建议有两件事...首先,为什么不使用 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 以获得最佳结果。