elixir
2024
Interesting links from week 3 of 2024.
Here are some interesting things I’ve found this week. I’m just getting started with this, so it may be a slow ramp up.
Elixir
TIL
Running mix ecto.dump creates a structure.sql file in ./priv/repo.
This is easy to forget to keep updated, so one easy way is to add this in the aliases() function in mix.exs:
"db.migrate": ["ecto.migrate", "ecto.dump"]
"db.rollback": ["ecto.rollback", "ecto.dump"]How to get a random number in Elixir.
iex(1)> :rand.uniform(6)
iex(2)> Enum.random(1..6)Sometimes you need a unique integer, and of course Elixir has you covered. This is very useful for Factories if you want to implement something like sequences to avoid errors due to database unique constraints.
iex(1)> System.unique_integer(~w[monotonic positive]a)
1
iex(2)> System.unique_integer(~w[monotonic positive]a)
2
iex(3)> System.unique_integer(~w[monotonic positive]a)
3Page 1 of 1