Skip to content

Conversation

@kachar
Copy link
Contributor

@kachar kachar commented May 17, 2021

Motivation

Created a hook that will use the functionality exposed by supabase-js for doing insert or update queries via upsert() method.

Related

Docs

/docs/pages/documentation/data/use-upsert.md

@vercel
Copy link

vercel bot commented May 17, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/zoo/react-supabase/ERQZxHW3ztxWvAgnaAxrhGzS8QiX
✅ Preview: https://react-supabase-git-fork-kachar-add-use-upsert-hook-zoo.vercel.app

@kachar
Copy link
Contributor Author

kachar commented May 17, 2021

Not sure why, but the docs title is not well rendered as useUpsert, but Use-Upsert instead.

image

It will be nice to fix that prior a merge


Edit: Fixed

Copy link
Member

@tmm tmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. One small thing, then I'll merge and release.

Comment on lines +23 to +29
## Notes

- By specifying the `onConflict` option, you can make `UPSERT` work on a column(s) that has a `UNIQUE` constraint.
- Primary keys should to be included in the data payload in order for an update to work correctly.
- Primary keys must be natural, not surrogate. There are however, workarounds for surrogate primary keys.
- Param `filter` makes sense only when operation is update
- Upsert supports sending array of elements, just like `useInsert`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these

Co-authored-by: Tom Meagher <tom@meagher.co>
@tmm tmm merged commit 800a190 into awkweb:main May 17, 2021
@kachar kachar deleted the add-use-upsert-hook branch May 18, 2021 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants