PeterDavidCarter

PeterDavidCarter

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.

First Post!

hubertlepicki

hubertlepicki

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

  1. Relational database. Most obvious / popular choice is to use Ecto GitHub - elixir-ecto/ecto: A toolkit for data mapping and language integrated query. · GitHub
  2. Serialize to binary blob with :erlang.term_to_binary/1 and save to file
  3. Use DETS dets — OTP 29.0.2 (stdlib 8.0.1)
  4. Use Mnesia (via Amnesia or directly, GitHub - meh/amnesia: Mnesia wrapper for Elixir. · GitHub)

  5. There are many many many more options.

Most Liked

stefanjarina

stefanjarina

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

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement