Strapi | Execute POSTGRESQL query before creating collection

Viewed 21

I am using PostgreSQL database for Strapi backend. I will use geometry data type of PostgreSQL. I am getting a polygon coordinates from frontend. But I need to execute a PostgreSQL query before creating collection. Because polygon coordinates have to be converted to geometry type.

Or can PostgreSQL execute text queries while adding data?

I need to execute this query: ST_GeomFromText('POLYGON((${crx.request.body.data.coordinates}))',4326)

1 Answers

after a few more hours of research, I found the solution. Strapi allows you to send raw queries to the database you are connected to. This code fixed the problem:

const query = await strapi.db.connection.raw(`SELECT ST_GeomFromText('POLYGON((${coordinates}))',4326)`);

Related