【问题标题】:Sequelize where condition as rawSequelize where condition as raw
【发布时间】:2015-05-06 15:15:11
【问题描述】:

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

我是否可以直接在模型上进行续集而不在原始版本中执行此操作?

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

【问题讨论】:

    标签: javascript node.js postgresql sequelize.js


    【解决方案1】:

    这个问题很老,但是,我建议有两件事......首先,你为什么不使用PostGIS 一个 postgresql 扩展,它在 GIS 数据方面非常出色和快速。其次..不!你不能这样做...但是对于高级 where 子句 条件,我建议将其与 Knex.js 原始查询生成器混合使用。您可以使用Knex.js 来构建您的where 子句,并将其与PostGIS 混合使用以获得最佳结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 2022-12-01
      • 2021-09-26
      • 1970-01-01
      • 2016-12-17
      相关资源
      最近更新 更多