supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
965 stars 129 forks source link

Type change for columns that do not exist in the schema #436

Closed 3ru closed 1 year ago

3ru commented 1 year ago

What kind of change does this PR introduce?

The type for columns that do not exist in the schema, which used to be ? to null.

What is the current behavior?

Currently, given a column that does not exist, the property can still be specified.

image

What is the new behavior?

If a non-existent column is given, the user cannot specify a non-existent column in order to return null.

image

This makes it easier to recognize column name problems from why they are null or from errors.

Additional context

It may be that this should return an error type similar to ParserError , GenericStringError, etc., but I think that would greatly expand the area to be modified.

soedirgo commented 1 year ago

Thanks for the PR! I've updated it so it throws an error which shows the missing column. Let me know if that looks good and I'll merge this.

3ru commented 1 year ago

@soedirgo Beautiful🙌 Thank you and merging is fine!

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.7.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

lopezjurip commented 1 year ago

It broke custom calculated columns using psql functions

Here is an example:

create table profiles (
  id uuid not null primary key default uuid_generate_v4(),
  user_id uuid unique references auth.users (id) on delete cascade not null,
);

create or replace function _email(this profiles)
  returns text strict stable
  language plpgsql
  as $$
    begin
      return (select users.email from auth.users as users where users.id = this.user_id and users.id = auth.uid() limit 1);
    end;
  $$;
const { data } = await supabase.from("profiles").select("id, email: _email");
// data type is: SelectQueryError<"Referencing missing column `_email`">

Previous version just declared email as unknown and I could overwrite that later.