How to avoid the metadata that Strapi-postgres returns when the row count is 0?

System Information
  • Strapi Version: v.4.2.0
  • Operating System: Ubuntu 20
  • Database: Postgres
  • Node Version: v12.13.1
  • NPM Version: 6.12.1
  • Yarn Version: NA

I am using the following to get data from Postgres in custom-controllers of my collection in Strapi;
const result = await knex.raw(SELECT * FROM testset)
There is no data in the table. But I still get a bunch of metadata in my result.
{“command”:“SELECT”,“rowCount”:0,“oid”:null,“rows”:[],“fields”:[{“name”:“id”,“tableID”:26968,“columnID”:1,“dataTypeID”:23,“dataTypeSize”:4,“dataTypeModifier”:-1,“format”:“text”},…

My question is, how can I NOT get this metadata and instead, maybe, get an empty array [ ]?

Thanks.


Hello @manishverma,

Since you are using the Knex itself, this is not something that can be changed by strapi. You can find more information about knex responses on their repo. The question here is, do you really need to use the raw queries? I would recommend using strapi’s methods to access the db (services, query, entityService).