-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Needs better description of the mutation syntax #530
Comments
I found an article somewhere else that explain it better but my issue still remains so I think maybe I need a more full example in the docs? Also for reference here's my unique index:
And here's what I'm trying to do (It's not my best attempt but i'm just messing around trying to get it to work):
|
Update: It looks like the useUpsert can only upsert on conficts of primary keys. I think the only way to do this is to check for existing data and use insert and update hooks to conditionally save one or the other. Here's how I'm doing it which requires 2 useXMutation hooks:
I also think it'd be good to have the rest of the example for these hooks to show using the mutateAsync since for update with supabase you do
but with the cache helpers you include the match in the data and rely on the primary key to match the row. |
hey @geoguide, thanks for opening the issue. You are right, cache helpers only works on primary keys. But support for multiple sets of unique columns would be a great enhancement. I would appreciate support with the documentation a lot! const { mutateAsync: insert } = useUpsertMutation(
client.from('contact'),
['id'],
'ticket_number', // -> here
{
onSuccess: () => console.log('Success!'),
}
); the
|
Describe the bug
The documents don't fully explain how the mutation hooks work or I am too dense to unerstand them.
Additional context
The docs show things like this over and over:
but never explain what 'ticket_number' is in the third argument. The types show
query: Q
which is a string. The docs could give better examples to make it obvious how to use these mutations. The library is awesome but I'm shooting in the dark trying to figure out how to get this to work. For instance, I'm using this useUpsertMutation and I'm getting duplicate key error. I thought maybe that 3rd argument was the unique column but that doesn't seem to work, maybe it's the fields that the query should return to determine which fields are getting updated but that doesn't affect it and coul be determined by the arguments passed to it? If someone can explain to me i'm happy to open a PR to add more documentation.Thanks for all the hard work!
The text was updated successfully, but these errors were encountered: