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

Support nulls=stripped introduced by PostgREST 11.2.0 #460

Open
steve-chavez opened this issue Aug 14, 2023 · 2 comments
Open

Support nulls=stripped introduced by PostgREST 11.2.0 #460

steve-chavez opened this issue Aug 14, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed p4 Priority 4

Comments

@steve-chavez
Copy link
Member

PostgREST 11.2.0 introduced stripping of null value properties in JSON results for arrays and single object responses. To support that functionality in postgrest-js a method like stripNulls()could be introduced. For instance: client.from('table').select().stripNulls().

Further information:

https://github.com/PostgREST/postgrest/releases/tag/v11.2.0 (see "Resource Representation")
https://postgrest.org/en/stable/references/api/resource_representation.html#stripped-nulls
https://github.com/PostgREST/postgrest/blob/main/test/spec/Feature/Query/NullsStrip.hs

PostgREST/postgrest#1601
PostgREST/postgrest#2894
PostgREST/postgrest#2899

Originally posted by @vrilcode in supabase/supabase#16479

@steve-chavez steve-chavez changed the title PostgREST 11.2.0 introduced stripping of null value properties in JSON results for arrays and single object responses. To support that functionality in [postgrest-js](https://github.com/supabase/postgrest-js) a method like stripNulls()could be introduced. For instance: client.from('table').select().stripNulls(). Support nulls=stripped introduced by PostgREST 11.2.0 Aug 14, 2023
@steve-chavez steve-chavez added the good first issue Good for newcomers label Aug 17, 2023
@imageck
Copy link

imageck commented Aug 18, 2023

Great addition. Thank you for the continuous improvement and maintenance.

My two cents: I would also like if it could be set as a global option.

@soedirgo soedirgo added enhancement New feature or request help wanted Extra attention is needed p4 Priority 4 and removed good first issue Good for newcomers labels May 28, 2024
@NiklasPor
Copy link

NiklasPor commented Aug 19, 2024

If anyone already needs this before we've got a method for this, you can tune your supabase instance to skip nulls for array responses (e.g. for a specific rpc) like this:

export const supabase = createClient(
  URL,
  ANON_KEY,
  {
    global: {
      fetch: (request, init) => {
        // Use any condition here to determine if the requests should skip nulls:
        const shouldStripNulls = request.toString().includes('rpc/your-rpc-call');
        
        if (shouldStripNulls) {
          const headers = new Headers(init?.headers);
          headers.set('Accept', 'application/vnd.pgrst.array+json;nulls=stripped');
          return fetch(request, { ...init, headers });
        }

        return fetch(request, init);
      },
    },
  },
);

I had some requests with lots of optional columns, cut down the response size by ~50% 👍

Docs: https://docs.postgrest.org/en/v12/references/api/resource_representation.html#stripped-nulls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed p4 Priority 4
Projects
None yet
Development

No branches or pull requests

4 participants