将几何体 (JSON) 插入 loopbackjs 模型

Inserting geometry (JSON) into loopbackjs model

我正在使用 angular SDK 在环回中添加和编辑几何到 PostGIS 中,并且我有以下工作正常:

ProjectGeoms.upsert({"id":"129","projectGeom":   {"type":"Polygon","coordinates":[[arrays of x/y co-ordinates]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}}, successCallback, errorCallback)

SQL 查询 运行 是:

loopback:connector:postgresql SQL: UPDATE "public"."project_geom" SET  "ref"=,"project_geom"=
Parameters: 129,{"type":"Polygon","coordinates":[[arrays of x/y co-ordinates]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}} +2ms

这是针对已存在的几何图形。但是,当我为不存在的几何体添加它时(相同的 JSON 结构,但 ID 为 124),则它不起作用。

SQL 查询 运行 是:

loopback:connector:postgresql SQL: INSERT INTO "public"."project_geom" ("ref","project_geom") SELECT , RETURNING 
Parameters: 124,{"type":"Polygon","coordinates":[[arrays of x/y co-ordinates]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}} +2ms

完整的错误信息如下:

loopback:connector:postgresql error: syntax error at end of input
at Connection.parseE (C:\Bitnami\wappstack-5.4.30-   0\apache2\htdocs\project\api\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:534:11)
at Connection.parseMessage (C:\Bitnami\wappstack-5.4.30-0\apache2\htdocs\project\api\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:361:17)
at Socket.<anonymous> (C:\Bitnami\wappstack-5.4.30-0\apache2\htdocs\project\api\node_modules\loopback-connector-postgresql\node_modules\pg\lib\connection.js:105:22)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10) +15ms

如果我 运行 直接在 Postgres 中进行以下查询:

INSERT INTO project_geom (ref,project_geom) VALUES (124,'{"type":"Polygon","coordinates":[[arrays of x/y co-ordinates]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}'::json);

我可以毫无问题地插入值。

table 数据模式是 (ref::integer, project_geom::json)

RTFM 案例 - 我错过了这个页面 http://docs.strongloop.com/display/public/LB/Model+definition+JSON+file#ModeldefinitionJSONfile-IDproperties,它清楚地表明

LoopBack CRUD methods expect the model to have an "id" property if the model is backed by a database.

呃。我的模型没有。查看loopback-postgresql-connector的code,它需要 ID字段到return一个id "RETURNING" 子句。虽然这是由环回记录的,但在我看来,这种特殊情况下的问题可以更清楚,所以我打算提交一个补丁来改变冗长的 log/error 消息。