Skip to content

Add useUpsert hook - #6

Merged
tmm merged 3 commits into
awkweb:mainfrom
kachar:add-use-upsert-hook
May 17, 2021
Merged

Add useUpsert hook#6
tmm merged 3 commits into
awkweb:mainfrom
kachar:add-use-upsert-hook

Conversation

@kachar

@kachar kachar commented May 17, 2021

Copy link
Copy Markdown
Contributor

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

vercel Bot commented May 17, 2021

Copy link
Copy Markdown

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

kachar commented May 17, 2021

Copy link
Copy Markdown
Contributor Author

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

@tmm tmm left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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

Comment thread src/hooks/data/use-upsert.ts Outdated
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