supabase / postgrest-js

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

Should `update` use Partial<Row>? #349

Closed xxRockOnxx closed 1 year ago

xxRockOnxx commented 1 year ago

Bug report

Describe the bug

Context: https://github.com/supabase/postgrest-js/blob/v1.0.0/src/PostgrestQueryBuilder.ts#L248

When updating, it currently asks for the whole columns.

Looking at the source, there's a PATCH request which I assume updates only what's given to it.

I could submit a PR adding Partial<> on it if it should be.

To Reproduce

Expected behavior

Allow specific column to be updated

Screenshots

None

System information

Additional context

None

soedirgo commented 1 year ago

Do you have a repro case where it's not making columns optional? The typegen should be making Relation['Update'] columns optional, e.g.:

https://github.com/supabase/postgrest-js/blob/94db7098ef9d75766b8ca84b1e888f34a3eb759d/test/types.ts#L19-L24

xxRockOnxx commented 1 year ago

@soedirgo the typegen on my end was wrong. i had to update some columns/properties manually and made a mistake. closing this now.

on a related note, is there a way to have typgen make some columns as never? e.g created_at or user_id just so we could avoid this kind of rookie mistake due to manual editing.

soedirgo commented 1 year ago

The types reflect the database, so if you make the column generated always, it'll be typed as never. E.g.:

create table my_table (created_at timestamptz generated always as (now()) stored);