supabase-community / postgrest-csharp

A C# Client library for Postgrest
https://supabase-community.github.io/postgrest-csharp/api/Postgrest.html
MIT License
114 stars 22 forks source link

Bulk Insert #13

Closed elrhomariyounes closed 3 years ago

elrhomariyounes commented 3 years ago

Feature request

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

Idea

  1. Overloading Insert method
    public Task<ModeledResponse<T>> Insert(ICollection<T> models, InsertOptions options = null)
  2. Perform request
    • Change the signature of the PrepareRequestData to return object instead of a dictionary and check if the data parameter is it an object or a collection to avoid the JsonSerializer Exception and serialize properly the collection if it's the case or serialize to dictionary<string,string> if not
      public object PrepareRequestData(object data)
    • Change Helpers.MakeRequest to expect the data to be object instead of a dictionary the PrepareRequestData will return an object
      public static async Task<ModeledResponse<T>> MakeRequest<T>(HttpMethod method, string url, object data = null, Dictionary<string, string> headers = null)
    • Add an if case in Helpers.MakeRequest to check data object type if dictionary, then cast it and build the Uri for the Request to preserve the same behavior

I would love to work on it and if there is a better approach let me know. Thank you very much

acupofjose commented 3 years ago

@elrhomariyounes sorry for the delay - we're on Thanksgiving holidays here. Your approach sounds good - though I imagine you'll be spending some times getting those test cases to be happy after those code changes! I'd suggest overloads on the helpers if possible. Let me know if there are particulars I can help on !

elrhomariyounes commented 3 years ago

Hello @acupofjose , Happy Thanksgiving hope you're doing well.

I implemented the new feature, I followed the same steps as I described previously, please check the PR.