How to make query Sql(Postgres)

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

In my Strapi project(version 4.0.5) I’m using PostgreSql and I need to write sql raw to reset sequence of my tables.
I see in another topics that in older version of strapi is possible to use “strapi.connections.default.raw(…)” but in new version it doesn’t work.
If I try to use strapi.connections.default.raw(…) i get an error like this: “Cannot read properties of undefined (reading ‘default’)”.
Does anyone know how to query database with new versions of strapi?

Hi @lepo,

I just did some digging for you, and I believe it is:

strapi.db.connection.context.raw(...)

Strapi uses knex.js for query building, which may have a built in helper function for what you are looking for.

All the best!

4 Likes