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
Hey folks! We’ve just released the beta 0.1.0 version of ash_sqlite. Take a look at the guide here: https://hexdocs.pm/ash_sqlite/get-sta...
New
zachdaniel
Ash and AshPostgres generators/installers, built with igniter are available on main! I’ll be very grateful to anyone willing to give the...
New
mspanc
Membrane v1.2.6 has been released. What’s Changed Adjust to Elixir 1.19 by @Noarkhh in Update to elixir 1.19 by Noarkhh · Pull Request ...
New
lawik
Nerves, fwup and NervesHub have had delta updates as a feature on the checklist for a long time. A delta update being essentially a patch...
New
zachdaniel
Hey folks! We’re starting a new weekly newsletter with the goings on of the various Ash packages and other interesting news from myself a...
New
fhunleth
We’re excited to announce that we’re actively working on NervesHub 2.0, an improved version of our IoT device firmware update and managem...
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
fhunleth
We’ve released new versions of all of the officially maintained Nerves Systems. The official systems, nerves_system_rpi0, nerves_system_b...
New
jjcarstens
The Raspberry Pi is a very popular hardware platform for Nerves users and the official systems are getting an upgrade! :tada: :beers: Wh...
New
mobileoverlord
Action Advised: NervesHub Sunset In 2018, NervesHub was launched to deliver first-class support for hardware deployments directly from th...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New

We're in Beta

About us Mission Statement