zachdaniel

zachdaniel

Creator of Ash

Atomic updates on upserts are now supported

We recently launched atomic updates, which look like this:

update :update do
  change atomic_update(:score, expr(score + 1))
end

# or when done manually

changeset
|> Ash.Changeset.atomic_update(:score, expr(score + 1))

This exact same syntax is now supported on create actions. It is currently ignored if done with a non-upsert action, and is only applied in the case of an upsert. You can think of the atomics as a way to control the update that is paired with the create for a given upsert. Here is an example of how you might use it:

# on a resource called PageView, for example
create :create_or_increment do
  accept [:page]
  upset? true
  upsert_identity :unique_page

  change set_attribute(:views, 1)
  change atomic_update(:views, expr(views + 1))
end

The action above would create a record with page set to the input value.

However, if a page view already exists with that name, it would increment its views by 1.

While this change is relatively small on its own, it is part of a progression of improvements that will make for a significant performance and quality of life improvement over time. More on this in a later update.

Enjoy!

Where Next?

Popular in News & Updates Top

bartblast
Hologram v0.8.0 is out! This release brings JavaScript interoperability - the most requested feature since the project’s inception. You c...
New
bartblast
Hologram UI is in the works - the official component library for Hologram - and the waiting list is now open. A common reaction when I m...
New
hugobarauna
Hugging Face is a platform for building, sharing, and collaborating on machine learning applications. This blog post explains how to run...
New
Jskalc
LiveVue v1.0 released After four release candidates and a lot of community feedback, LiveVue 1.0 is stable :tada: I’ve built a dedicated...
New
zachdaniel
Working with nested forms in Ash was already great, but it’s even better now with a the new features that will be in the next release of ...
New
fhunleth
We are thrilled to announce another update for Nerves Systems to nerves_system_br 1.22.5-based releases. Nerves systems are the device su...
New
zachdaniel
Ash Framework 3.0: Release Candidates! The day is finally here! This is the culmination of years of work from the Ash team and community ...
New
bartblast
Hey Elixir community! :waving_hand: First, I owe you all an apology. There’s a running joke among my friends that Hologram is like nucle...
New
zachdaniel
Hello everyone! We’ve got two big updates on the Ash community today :tada: Discord Support Forum → Elixir Forum The Ash community is g...
New
jjcarstens
NervesPack 0.4.0 is a minor bump with a fairly big change. This update drops :nerves_firmware_ssh in favor of the newer and more focused...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement