Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to rowCount from Query #590

Open
amerryma opened this issue Oct 4, 2024 · 0 comments
Open

Access to rowCount from Query #590

amerryma opened this issue Oct 4, 2024 · 0 comments

Comments

@amerryma
Copy link

amerryma commented Oct 4, 2024

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 amerryma changed the title Access to affectedRows from Query Access to rowCount from Query Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant