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: upsert with on-conflict support #142

Merged
merged 6 commits into from
Feb 7, 2023

Conversation

Oisangui
Copy link
Contributor

@Oisangui Oisangui commented Jul 15, 2022

Closes #139

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 15, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.52%.

Quality metrics Before After Change
Complexity 0.87 ⭐ 0.93 ⭐ 0.06 👎
Method Length 33.16 ⭐ 33.54 ⭐ 0.38 👎
Working memory 6.46 🙂 6.59 🙂 0.13 👎
Quality 85.63% 85.11% -0.52% 👎
Other metrics Before After Change
Lines 770 780 10
Changed files Quality Before Quality After Quality Change
postgrest/base_request_builder.py 86.78% ⭐ 86.17% ⭐ -0.61% 👎
postgrest/_async/request_builder.py 82.94% ⭐ 82.57% ⭐ -0.37% 👎
postgrest/_sync/request_builder.py 82.96% ⭐ 82.59% ⭐ -0.37% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
postgrest/_async/request_builder.py AsyncRequestBuilder.upsert 0 ⭐ 51 ⭐ 12 😞 72.70% 🙂 Extract out complex expressions
postgrest/_sync/request_builder.py SyncRequestBuilder.upsert 0 ⭐ 51 ⭐ 12 😞 72.70% 🙂 Extract out complex expressions
postgrest/_async/request_builder.py AsyncRequestBuilder.insert 0 ⭐ 46 ⭐ 10 😞 77.13% ⭐ Extract out complex expressions
postgrest/_sync/request_builder.py SyncRequestBuilder.insert 0 ⭐ 46 ⭐ 10 😞 77.13% ⭐ Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

mansueli
mansueli previously approved these changes Jul 15, 2022
lopezjurip
lopezjurip previously approved these changes Jul 15, 2022
postgrest/base_request_builder.py Outdated Show resolved Hide resolved
postgrest/_sync/request_builder.py Show resolved Hide resolved
Oisangui and others added 4 commits July 16, 2022 10:22
@Oisangui Oisangui requested a review from anand2312 July 17, 2022 21:00
@Oisangui
Copy link
Contributor Author

Oisangui commented Aug 4, 2022

@anand2312 Could you give me a hand telling me what is missing? I'm not very knowledgeable with python repos.

@troels
Copy link

troels commented Sep 24, 2022

What is holding this one back? It would be a very nice feature to have!

@Oisangui
Copy link
Contributor Author

Oisangui commented Sep 24, 2022

What is holding this one back? It would be a very nice feature to have!

@troels

Waiting for someone to review the changes that @anand2312 requested.

@anand2312
Copy link
Contributor

Sorry for the delay -- can you add some test cases for this case as well please? Otherwise this LGTM, ready to merge @Oisangui

@J0 J0 dismissed stale reviews from lopezjurip and mansueli via 5a4d62f January 7, 2023 02:01
@J0
Copy link
Contributor

J0 commented Jan 23, 2023

Think this should be good to go - if merged I'll add test in a FLUP

@J0 J0 self-requested a review January 23, 2023 05:26
@J0
Copy link
Contributor

J0 commented Jan 23, 2023

Let's also pull in master and make sure the tests pass first though.

@altryne
Copy link

altryne commented Feb 6, 2023

Would love this to get merged, literally facing this RN and got to this issue.
The only workaround is SQL func and RPC call?

CleanShot 2023-02-05 at 21 28 28@2x

@J0
Copy link
Contributor

J0 commented Feb 6, 2023

Hey,

@altryne noted - we'll merge by tomorrow evening if there are no major issues. Will validate this today evening + add necessary tests/ fixes. From now till then then I think the main workaround would be to use a sql func and an RPC call.

Upd: Busy day, probably going to look at this tmrw instead

@J0 J0 merged commit ecc6e79 into supabase-community:master Feb 7, 2023
@LeSchuch
Copy link

Hey,

I'm a little bit lost on where to use the on_conflict parameter in a request.
For example, this is not working :
supabase.table("user").upsert([{"id": 5, "name": "John"}], on_conflict=["id"]).execute()

Could you provide a simple example on how to use this parameter ?

@Oisangui
Copy link
Contributor Author

Hey,

I'm a little bit lost on where to use the on_conflict parameter in a request. For example, this is not working : supabase.table("user").upsert([{"id": 5, "name": "John"}], on_conflict=["id"]).execute()

Could you provide a simple example on how to use this parameter ?

You are passing a list, it should be a string.

@LeSchuch
Copy link

Hum, I have this error even if I'm passing it as a string :
TypeError: SyncRequestBuilder.upsert() got an unexpected keyword argument 'on_conflict'

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

Successfully merging this pull request may close these issues.

Upsert on conflict
8 participants