supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
962 stars 128 forks source link

#523 fix typescript error for aggregate functions #531

Open stefan-girlich opened 2 months ago

stefan-girlich commented 2 months ago

What kind of change does this PR introduce?

Fix dynamic TypeScript type for data when using aggregate functions other than count

What is the current behavior?

Aggregate functions other than count will result in TypeScript errors for the resulting type of data (#523)

Bug fix for issues:

What is the new behavior?

Using the other aggregate functions "sum", "avg", "min", and "max" will not result in an erroneous TypeScript type for data.

Additional context

I just generalized changes from #520 by @bnjmnt4n ; thanks for your work!

bnjmnt4n commented 2 months ago

Do the queries work when just querying Postgrest? My understanding when implementing this, based on https://postgrest.org/en/v12/references/api/aggregate_functions.html, was that the syntax was column.max(), and not column(max).

stefan-girlich commented 2 months ago

@bnjmnt4n You're right; column(max) is not valid; my fix is therefore not ideal as it allows for invalid syntax. Would you have any idea concerning how to fix the issues with the other aggregation functions besides count() (#523 , #524 )?

bnjmnt4n commented 2 months ago

Do you have a reproducible failing test case or example?

stefan-girlich commented 2 months ago

Sure; I mentioned them in #523 for visibility: https://github.com/supabase/postgrest-js/issues/523#issuecomment-2048080742