2017-08-18 87 views
0

我在使用NodeJS,BookshelfJS和ExpressJS進行項目。 我的數據庫是安裝了Postgis的Postgres。 我的表'組織'有一個'lat_lon'幾何列。 我想查詢特定經/緯度點的固定半徑內的所有組織。 我想是這樣的:使用NodeJS,BookshelfJS和Knex進行PostGIS查詢

var organizations = await Organization.query(function (qb) { 
qb.where('ST_DWithin(lat_lon, ST_GeomFromText("POINT(45.43 10.99)", 4326), 1000)') 
}).fetchAll() 

和更多的組合,但它不工作。 它返回我一個錯誤

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: The operator "undefined" is not permitted

看來它期待運營商內部的where條件,但我已經工作的「lat_lon」列。

我該如何解決? 謝謝

回答

0

您是否嘗試過使用knex.raw()?

var organizations = await Organization.query(function (qb) { 
qb.where(knex.raw('ST_DWithin(lat_lon, ST_GeomFromText("POINT(45.43 10.99)", 4326), 1000)')) 
}).fetchAll() 
+0

它不起作用。我有這個錯誤:「UnhandledPromiseRejectionWarning:未處理的承諾拒絕(拒絕ID:2):錯誤:從」組織「中選擇」機構「*其中ST_DWithin(lat_lon,ST_GeomFromText(」POINT(45.43 10.99)「,4326) - 列「POINT(45.43 10.99)」不存在「。 我的專欄稱爲「lat_lon」,是一個幾何圖形。 – Matteo

+0

它的工作原理如果我這樣做:'ST_DWithin(lat_lon,ST_MakePoint(45.43,10.99),1000)'。有什麼不同? – Matteo