Inserting a geomtry datatype to postgres using sequelize

Viewed 95

I'm trying to insert a new row to my table which has 2 attributes from geometry. One is a Point and the other one is a Polygon type.

This is what I'm receiving:

"location": {
        "type": "Point",
        "coordinates": [0, -10]
    },
"scope": {
        "type": "Polygon",
        "coordinates": [[0, -10], [3, 0]]
    },

My model has this structure from both properties

location: {
        type: DataTypes.GEOMETRY('POINT'),
        allowNull: false
    },
scope: {
        type: DataTypes.GEOMETRY('POLYGON'),
        allowNull: false
    },

But when trying to insert a row to this table with this properties, I'm getting the error original: error: column "location" is of type point but expression is of type geometry

I tried sending the object as I'm receiving it, and tried sending an array of the coordinates but neither of them works.

This is the query that is being executed when trying to insert the row to the table

`INSERT INTO "store" ("id","city_id","street","location","scope","active","contact_form")
VALUES (DEFAULT,$1,$2,ST_GeomFromGeoJSON($3),ST_GeomFromGeoJSON($4),$5,$6) RETURNING
"id","city_id","name","street","reference","zip_code","location","scope","active", "contact_form";

Any suggestion on how to manage this? Never used Geometry before.

UPDATE:

I managed to insert a Point into the database, but had to change the datatype in the database to geometry. Now, when I'm trying to insert a Polygon like this POLYGON((-12.055749 -77.018997, -12.067625 -76.989852, -12.114647 -77.000538, -12.055749 -77.018997)) and I'm getting this error error: unexpected character (at offset 0)

0 Answers
Related