.on_conflict or upsert #248
Answered
by
dantownsend
Thaiwegian
asked this question in
Q&A
-
What is the equivalent in Piccolo to .on_conflict or upsert? |
Beta Was this translation helpful? Give feedback.
Answered by
dantownsend
May 4, 2023
Replies: 2 comments 2 replies
-
@Thaiwegian There isn't an API for upsert yet, but I'll create a new issue for it. For now, here's a workaround: class Person(Table):
name = Varchar()
age = Integer()
values = {Person.age: 33}
person = Person.objects().get_or_create(Person.name == 'Bob', values).run_sync()
if not person._was_created:
Person.update(defaults).where(Person.name == 'Bob').run_sync() I hope that helps. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Upsert is supported now: https://piccolo-orm.readthedocs.io/en/latest/piccolo/query_clauses/on_conflict.html |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dantownsend
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Upsert is supported now: https://piccolo-orm.readthedocs.io/en/latest/piccolo/query_clauses/on_conflict.html