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

updateMutation with typed supabase client does not expect ID (type:never) #520

Open
JessedeJonge opened this issue Nov 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@JessedeJonge
Copy link

Describe the bug
When using the following database definition:

CREATE TABLE IF NOT EXISTS public.companies (
  id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name TEXT NOT NULL
)

The types generated for above table by the supabase cli are:
Update: {
id?: never
name: string
}

Ofcourse, above types makes the useUpdate mutation give:
Type 'number' is not assignable to type 'undefined'.

  const { mutateAsync: updateCompany, isPending: isUpdating } =
    useUpdateMutation(supabase.from("companies"), ["id"], null);

   await updateCompany({
         id: companyID,
        ...values,
      });

How should i define my postgres tables to make this work?

@JessedeJonge JessedeJonge added the bug Something isn't working label Nov 7, 2024
@psteinroe
Copy link
Owner

Hey! This is a problem with the generated types, not with this library. Can you open that issue at the postgres-meta repo?

@JessedeJonge
Copy link
Author

JessedeJonge commented Nov 7, 2024

@psteinroe Why do you think its a problem from the types? I think for the types it makes sense to make primary keys in updates typed a never to prevent updating primary keys. However, for this library its needed so it knows which row to update. In your test it looks like the types are generated differently, with which version did you generate it? Or maybe you defined the ID's differently in your postgres?

@psteinroe
Copy link
Owner

Ah that's a good point! The problem is that the types are never for generated ids. I am using uuids with a default, which generates a string | null. I don't know how to fix this from the top of my head without breaking the API of cache helpers unfortunately. But I will think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants