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

feat(postgrest)!: stronger type system for query building #624

Merged
merged 10 commits into from
Sep 15, 2023

Conversation

Vinzent03
Copy link
Collaborator

@Vinzent03 Vinzent03 commented Sep 11, 2023

What kind of change does this PR introduce?

feature

What is the current behavior?

The type system makes everything dynamic, which is not very efficient. Additionally, the way a method argument changes the overall return type is not very darty.

What is the new behavior?

By changing the api and class structure, everything is perfectly typed.

Before

supabase.from('users').insert().select<PostgrestListResponse>('id, messages', FetchOptions(count: CountOption.exact));

supabase.from('users').select('id, messages', FetchOptions(count: CountOption.exact));

supabase.from('users').select('*', FetchOptions(count: CountOption.exact, head: true));

After

supabase.from('users').insert().select('id, messages').count(CountOption.exact);

supabase.from('users').select('id, messages').count(CountOption.exact);

supabase.from('users').count(CountOption.exact);

Breaking points

  • FetchOptions is removed from select etc. and made to stand alone methods

Additional context

The pr turned bigger than expected, but I think it's real magic how the return type perfectly changes by adding single and withConverter etc. So I think it's worth it.

@Vinzent03
Copy link
Collaborator Author

This should be ready now 🚀
I'm just unsure about one thing. Is there a real use case for the following query?

await postgrest.from('users').select('*').head();

I've made it void now, because it calls the query, but doesn't return it? I'm unsure what to put in the documentation as well.

@Vinzent03 Vinzent03 marked this pull request as ready for review September 13, 2023 13:37
Copy link
Member

@dshukertjr dshukertjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks amazing! I had a few small questions here and there, but nothing major! Thanks for the awesome work 🚀

@Vinzent03
Copy link
Collaborator Author

Other than the head thing, everything should be fixed

@Vinzent03 Vinzent03 merged commit 951ce89 into next Sep 15, 2023
8 checks passed
@Vinzent03 Vinzent03 deleted the feat/postgrest-types branch September 15, 2023 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants