zachdaniel

zachdaniel

Creator of Ash

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? Top

Trending in News & Updates Top

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
bartblast
I’ll be using this thread to share Hologram patch release announcements. Minor releases will continue to get dedicated threads with blog ...
New
sorenone
This release unifies configuration for queues, repos, and services, swaps opaque timing integers for readable durations, and backports pe...
New
pcharbon
:heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::hea...
New
jvoegele
Bond brings Design by Contract to Elixir: preconditions, postconditions and invariants as executable specifications, checked at runtime a...
New
webofbits
Aludel 0.7.0 is released :tada: Since 0.5.0, Aludel has grown into a much more complete LLM evaluation toolkit for Elixir and Phoenix app...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews