supabase / postgrest-js

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

Type safety is not being adhered on insert queries #508

Open dvrfluxchat opened 7 months ago

dvrfluxchat commented 7 months ago

I have a insert query in my db which looks like this and I am using the typescript version of supabase-js.

await supaServiceClient
        .from("table_name")
        .insert({
          column1:value,
          column2:value,
          column3:value
        });

I changed the column "column1" to "newColumn1" but the above query did not throw any errors where there is no "column1". This lead to issues in production where this query stopped working as the insert was failing saying there is no column1 but the compiler did not throw any error. Is this the expected behaviour? If so how do i ensure to get compile time warnings for such scenarios.

tecoad commented 1 month ago

I have the same issue. Did you find out @dvrfluxchat ?

weilantian commented 5 days ago

You will need call .select(...) after .insert(...), to specify the field you wish to be included to the data. With your exmaple if you wish to retrieve the values of all columns of the row created, use following code:

const {data, error} = await supaServiceClient
        .from("table_name")
        .insert({
          column1:value,
          column2:value,
          column3:value
        }).select("*");

You will then be able to access value of a column, let's say for exmaple column1

data?.[0].column1