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

zachdaniel
:police_car_light: New AshAuthentication Installers :police_car_light: The AshAuthentication igniter installers are released! Today on s...
New
zachdaniel
What if you had full stack types for SPAs built with tech like React, Inertia, Vue, Svelte… but all of the power Ash Framework and Elixir...
New
bartblast
Hologram v0.9 is out! The headline is a realtime layer - your server can now push updates to connected clients with no polling: broadcast...
New
bartblast
Hologram’s journey just took a significant leap forward: Curiosum is coming on board as the Main Sponsor, and I’m joining their team to w...
New
hugobarauna
Discover Livebook 0.9’s new security features, including Hubs for centralized secret management, notebook stamping, and a sneak peek into...
New
jjcarstens
I know you might be thinking ¬ “Why make another SSH daemon wrapper when there already exists many like sshex and esshd??” Well, grea...
New
DominikWolek
Hi everyone! After about 3 months of really hard work, we have released the very first version of Jellyfish Media Server! The best star...
New
zachdaniel
Ash 3.1 Released! Major themes Generators! These are just the first entries into a powerful new suite of tools. Check out the generator d...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
zachdaniel
We recently launched atomic updates, which look like this: update :update do change atomic_update(:score, expr(score + 1)) end # or w...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
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
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement