Sequelize WHERE sequelize.fn(…)和东西='东西'订购问题

我有一个Sequelize findOne函数,它可以select一个给定点与一个多边形(col'geom')AND状态='active'相交的行。

var point = sequelize.fn('ST_GeomFromText', 'POINT(' + lng + ' ' + lat +')', 4326); var intersects = sequelize.fn('ST_Intersects', sequelize.col('geom'), point); GeoCounty.findOne({ attributes: ['id', 'name' ], where: { status: 'active', $and: intersects }, plain: true }) 

截至目前,它工作得很好。 它生成的SQL如下所示:

 SELECT "id", "name" FROM "geocounty" AS "geocounty" WHERE "geocounty"."status" = 'active' AND (ST_Intersects("geom", ST_GeomFromText('POINT(-98.025006 43.714735)', 4326))) LIMIT 1; 

我真正想要的是:

 SELECT "id", "name" FROM "geocounty" AS "geocounty" WHERE (ST_Intersects("geom", ST_GeomFromText('POINT(-98.025006 43.714735)', 4326))) AND "geocounty"."status" = 'active' LIMIT 1; 

也就是说ST_Intersects子句先出现,AND状态='active'出现。

我的问题是:
1.执行查询的第一种方法是否有任何性能损失? 2.在Sequelize中有一种方法来构造这样的where子句吗?

这不起作用:

 GeoCounty.findOne({ attributes: ['id', 'name' ], where: { intersects, $and: { status: 'active' } }, plain: true }) 

它产生这个SQL:

 SELECT "id", "name" FROM "geocounty" AS "geocounty" WHERE "geocounty"."intersects" = ST_Intersects("geom", ST_GeomFromText('POINT(-98.025006 43.714735)', 4326)) AND ("geocounty"."status" = 'active') LIMIT 1; 

没有geocounty.intersects …

       

网上收集的解决方案 "Sequelize WHERE sequelize.fn(…)和东西='东西'订购问题"