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

Feat: implement on_conflict #113

Merged
merged 6 commits into from
Oct 2, 2020

Conversation

izqalan
Copy link
Contributor

@izqalan izqalan commented Oct 2, 2020

What kind of change does this PR introduce?

Added on_conflict feature for insert method.

What is the current behavior?

Missing on_conflict feature for insert method. #78

What is the new behavior?

When inserting, if upsert: true and UNIQUE column specified on on_conflict: column option set on_conflict searchParams.

Additional context

http://postgrest.org/en/v7.0.0/api.html?highlight=on%20conflict#on-conflict

Copy link
Member

@soedirgo soedirgo left a comment

Choose a reason for hiding this comment

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

Hey again @izqalan! 👋

I just have a couple of nits while this is in a draft. Otherwise, looks good!

test/basic.test.ts Outdated Show resolved Hide resolved
src/builder.ts Outdated Show resolved Hide resolved
src/builder.ts Outdated Show resolved Hide resolved
@izqalan izqalan marked this pull request as ready for review October 2, 2020 13:47
@izqalan izqalan requested a review from soedirgo October 2, 2020 13:50
@izqalan
Copy link
Contributor Author

izqalan commented Oct 2, 2020

@soedirgo updated with your suggestions.

@soedirgo
Copy link
Member

soedirgo commented Oct 2, 2020

Awesome, thanks again @izqalan!

@soedirgo soedirgo linked an issue Oct 2, 2020 that may be closed by this pull request
@soedirgo soedirgo merged commit 3a902b3 into supabase:master Oct 2, 2020
@github-actions
Copy link

github-actions bot commented Oct 2, 2020

🎉 This PR is included in version 0.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@TomasHubelbauer
Copy link
Contributor

Seems like this insert overload has since been deprecated (judging by the TypeScript types), use upsert like this:

await supabase.from('ips').upsert({ updated_at: new Date(), ip: request.ip, geo }, { onConflict: 'ip' });

@magick93
Copy link

magick93 commented Aug 5, 2022

How would I translate the following sql insert to the supabase js client?

INSERT INTO comment_votes (comment_id, user_id, vote)
VALUES('e9a8b088-aa2f-45ac-b961-e5b71cb5ef42','f1b80dc9-5830-432a-b137-d3c6b9ba2b4b', null) 
ON CONFLICT ON CONSTRAINT comment_votes_pkey
DO 
   UPDATE SET vote = excluded.vote;

Can I specify a composite key as a constraint for the conflict?

@steve-chavez
Copy link
Member

@magick93 Replied on supabase/supabase#8093

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement on_conflict
5 participants