How to persist data in functional Elixir

Could anyone give me a simple example of how to persist data in Elixir. Coming from a JavaScript background I’m still not fully understanding the functional paradigm.

and where you want to persit the data? You have a few options:

  1. Relational database. Most obvious / popular choice is to use Ecto
  2. Serialize to binary blob with :erlang.term_to_binary/1 and save to file
  3. Use DETS
  4. Use Mnesia (via Amnesia or directly,

  5. There are many many many more options.

There are 2 different meanings to this:

First is to really persist the data even when the application restarts

Second is to keep data only in running application [keep a state] (like an object instance in OO languages)

The above state won’t survive the application crashes/restarts though, so you usually use the mix of GenServer/Agent and Database/Amnesia/DETS, etc.

This is a great article that talks about the different states , it is for Erlang, but it explains theory well.

Cheers mate