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

Types for column name disambiguation #450

Closed
2 tasks done
wyozi opened this issue Jul 26, 2023 · 7 comments · May be fixed by #451
Closed
2 tasks done

Types for column name disambiguation #450

wyozi opened this issue Jul 26, 2023 · 7 comments · May be fixed by #451
Labels
bug Something isn't working

Comments

@wyozi
Copy link
Contributor

wyozi commented Jul 26, 2023

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

PostgREST allows disambiguating relationships by using a column name as the target directly (see column name section of https://postgrest.org/en/stable/references/api/resource_embedding.html#embedding-disambiguation). However, select query parser in postgrest-js does not support this yet.

Personally I find column name disambiguation to be the superior method for embeds, so it would be nice to have this

To Reproduce

Use column name instead of foreign key constraint name or relation name as the target, i.e. .select('user:username(*)') instead of .select('user:users(*)')

@wyozi wyozi added the bug Something isn't working label Jul 26, 2023
@albinekb
Copy link

I have been using the patch from #451 for three months now, it's working great! Any chance of getting that merged? It's a bit messy to have to manage the patch. Thanks!

@avallete
Copy link
Member

Hey everyone !

We've reworked the result inference in postgrest-js to address the typing issues mentioned above. The changes are available in a canary release, and we're actively seeking your feedback.

To test it out, update your supabase-js to version 2.46.0-rc.1 (which includes postgrest-js 1.17.0-rc.1):

npm install [email protected]

Please let us know if you encounter any issues, especially with retro-compatibility, so we can finalize it for the next release.

@wyozi
Copy link
Contributor Author

wyozi commented Oct 21, 2024

@avallete do db typescript types have to be regenerated or changed in any way?

@wyozi
Copy link
Contributor Author

wyozi commented Oct 21, 2024

I'm using an extended database types definition (something similar to https://github.com/activenode/supabase-table-extensions-typed) and it seems to break with this error:

      Property 'supabaseUrl' is protected but type 'SupabaseClient<Database, SchemaName, Schema>' is not a class derived from 'SupabaseClient<Database, SchemaName, Schema>'.

e: nvm, was some weird npm package caching thing

@wyozi
Copy link
Contributor Author

wyozi commented Oct 21, 2024

looks like there's a small regression with !inner; in some situations it doesn't make the relation non-nullable but in some situations it does. I'll try to research it a bit

e: it's just the IsColumnNullable making the type check even better than before (and I expected) 🥹. My foreign key column was nullable. Good job @avallete! No real regressions in a moderately sized project utilizing supabase types

@avallete
Copy link
Member

Hey @wyozi

Thank's for giving it a try and sending feedbacks ! Happy to hear that it's working for you and you managed to get everything working on the new version !

@avallete
Copy link
Member

The fix has been released in supabase-js v2.46.0. I'm closing this issue, but feel free to reopen or open a new issue if you encounter any further errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants