postgrest-py
postgrest-py copied to clipboard
feat: upsert with on-conflict support
- [x]
on_conflict
support as described here https://postgrest.org/en/stable/api.html#on-conflict.
Closes #139
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!
@anand2312 Could you give me a hand telling me what is missing? I'm not very knowledgeable with python repos.
What is holding this one back? It would be a very nice feature to have!
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.
Sorry for the delay -- can you add some test cases for this case as well please? Otherwise this LGTM, ready to merge @Oisangui
Think this should be good to go - if merged I'll add test in a FLUP
Let's also pull in master and make sure the tests pass first though.
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](https://user-images.githubusercontent.com/463317/216883884-a8229ff4-d7c4-4186-8587-0bb88bc46923.png)
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
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 ?
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.
Hum, I have this error even if I'm passing it as a string : TypeError: SyncRequestBuilder.upsert() got an unexpected keyword argument 'on_conflict'