pgtyped icon indicating copy to clipboard operation
pgtyped copied to clipboard

Access to rowCount from Query

Open amerryma opened this issue 4 months ago • 0 comments

Is your feature request related to a problem? Please describe. When writing test cases, I use generated TS code from this library to run my queries. With node-postgres, I was able to access rowCount in order to perform some assertions. For example, if you delete something, you can check rowCount to find out if it was actually deleted. When switching to pgtyped, I lost access to this because .rows is essentially returned, and the rowCount is no longer accessible.

Describe the solution you'd like Have some sort of alternative query capability that allows me to have access to rowCount again.

I did something similar locally but involved pretty much copying all the runtime code as I couldn't extend the class properly without some access to some of the non-exported functions (processSQLQueryIR and mapQueryResultRows)

this.runWithCounts = async (params, connection) => {
  const { query: processedQuery, bindings } = processSQLQueryIR(this.queryIR, params as any);
  const result = await connection.query(processedQuery, bindings);
  return { result: mapQueryResultRows(result.rows), rowCount: result.rowCount };
};

Additional context I can't think of any workaround right now.

amerryma avatar Oct 04 '24 16:10 amerryma