supabase / postgrest-dart

Dart client for PostgREST
https://supabase.com
MIT License
136 stars 38 forks source link

Add head and count option #16

Closed dshukertjr closed 3 years ago

dshukertjr commented 3 years ago

What kind of change does this PR introduce?

This feature is postgrest-dart equivalent of this feature in postgrest-js https://github.com/supabase/postgrest-js/pull/147

What is the current behavior?

There are not head or count options

What is the new behavior?

head and count options are added

dshukertjr commented 3 years ago

@phamhieu @ Hi! I have added a head and count option that was added to postgrest-js recently. Let me know what you think about it! Feedback is always welcome. Let me know if you don't like some of the decisions that I have made with the code. I can always update it.

phamhieu commented 3 years ago

Hi @dshukertjr thanks for your contribution 👍

I have a proposal for head and count implementation. Let me know your thought.

Instead of modify select, insert, update, delete and rpc, why don't we modify execute() to support these new options

Future<PostgrestResponse> execute({bool head = false, CountOption count}) async {
  if (head) {
     method = 'HEAD';
  }

  if (count != null) {
      if (headers['Prefer'] == null) {
          headers['Prefer'] = 'count=${count.name()}'; 
      }
     else { 
          headers['Prefer'] += ',count=${count.name()}'; 
     }
   }

  ...
}

by doing this:

dshukertjr commented 3 years ago

Hi @dshukertjr thanks for your contribution 👍

I have a proposal for head and count implementation. Let me know your thought.

Instead of modify select, insert, update, delete and rpc, why don't we modify execute() to support these new options

Future<PostgrestResponse> execute({bool head = false, CountOption count}) async {
  if (head) {
     method = 'HEAD';
  }

  if (count != null) {
      if (headers['Prefer'] == null) {
          headers['Prefer'] = 'count=${count.name()}'; 
      }
     else { 
          headers['Prefer'] += ',count=${count.name()}'; 
     }
   }

  ...
}

by doing this:

  • less change on the code base
  • It can also support all PostgrestQueryBuilder methods: select, insert, update, delete and rpc
  • prevent breaking change for select with custom columns. select(columns: 'messages(*)')

@phamhieu I like this approach. Let me update the code now!

dshukertjr commented 3 years ago

@phamhieu I have updated the code! Thanks for all the great suggestions, and let me know if you have more!

phamhieu commented 3 years ago

Excellent work! @dshukertjr

There're minor changes and cleanup. But overall looks good to me.

dshukertjr commented 3 years ago

@phamhieu Thank you so much for all of your support!

phamhieu commented 3 years ago

Thanks @dshukertjr, amazing job!

Btw, I'm writing gotrue-dart library right now. Porting from https://github.com/supabase/gotrue-js Let me know if you are interested to contribute. I can add you in. As it's still under-development I haven't made it public

dshukertjr commented 3 years ago

@phamhieu I was going to ask someone if there is a gotrue-dart being developed! I would love to contribute to gotrue-dart as well!