postgrest-py icon indicating copy to clipboard operation
postgrest-py copied to clipboard

feat: upsert with on-conflict support

Open Oisangui opened this issue 1 year ago • 5 comments

  • [x] on_conflict support as described here https://postgrest.org/en/stable/api.html#on-conflict.

Closes #139

Oisangui avatar Jul 15 '22 15:07 Oisangui

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!

sourcery-ai[bot] avatar Jul 15 '22 15:07 sourcery-ai[bot]

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

Oisangui avatar Aug 04 '22 21:08 Oisangui

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

troels avatar Sep 24 '22 23:09 troels

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.

Oisangui avatar Sep 24 '22 23:09 Oisangui

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

anand2312 avatar Oct 02 '22 10:10 anand2312

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

J0 avatar Jan 23 '23 05:01 J0

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

J0 avatar Jan 23 '23 05:01 J0

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

altryne avatar Feb 06 '23 04:02 altryne

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 avatar Feb 06 '23 05:02 J0

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 ?

LeSchuch avatar Feb 26 '23 09:02 LeSchuch

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.

Oisangui avatar Feb 26 '23 12:02 Oisangui

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

LeSchuch avatar Feb 26 '23 20:02 LeSchuch