Electron100 / butane

An ORM for Rust with a focus on simplicity and on writing Rust, not SQL
Apache License 2.0
83 stars 11 forks source link

Add upsert support #112

Closed jayvdb closed 1 year ago

jayvdb commented 1 year ago

In a multi-threaded / async program, the order of events is not predictable, so it is safer to able to use upsert instead of insert or update.

e.g. in the blog example, if there are two threads and they both want to create a tag "danger", this will result in an unique constraint violation in the insert operation for one of them. Doing a query for the tag "danger" to determine whether to insert can help, but the query+insert it isnt atomic so another thread could have created the tag between the query and the insert operations .