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?

Trending in News & Updates Top

bartblast
After building Hologram and sharing updates across various places, I’ve realized there’s a lot happening that doesn’t always make it to t...
New
kip
I’m a bit excited to announce that Localize and friends are now at release 1.0. Even though it’s a 1.0 release, it stands on 8 years of w...
New
nseaSeb
Just published search_ash 0.5.0 (with search_core 0.4.0) on Hex. What’s new: synonyms You can now declare a synonym dictionary per lang...
New
polvalente
We have released v0.13 of nx, exla and torchx, along with a recently released emlx v0.4. Nx This is where the bulk of the updates happen...
New
mudasobwa
After years of struggling I made StreamData dependency optional. Finitomata.ExUnit got testing primitives for Persistence. Full back co...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement