assert the size of the list in elixir

Kernel.length/1 will return the size of a list: length([1,2,3]) #3 You can do this from an Ecto query using: query = from d in Device, where: d.uuid == ^uuid, select: fragment(“count(?)”, d.id) assert Repo.all(query)== 3 In Ecto 2 you can use Repo.aggregate/4 query = from d in Device, where: d.uuid == ^uuid) assert Repo.aggregate(query, :count, … Read more

How to generate a random url safe string with Elixir

What you can do instead is to generate a Base64-encoded string to be used as a confirmation token. This confirmation token will then be saved to your DB and passed as params to the activation link. Your activation url would look something like: activation_url(MyApp.Endpoint, :confirm, confirm_id: confirm_id) The above url helper assumes you have a … Read more

How do I save IEx history?

For Erlang/OTP 20 This is built-in (from https://hexdocs.pm/iex/IEx.html#module-shell-history) From Erlang/OTP 20, it is possible to get shell history by passing some flags that enable it in the VM. This can be done on a per-need basis when starting IEx: iex –erl “-kernel shell_history enabled” If you would rather enable it on your system as a … Read more

Elixir – try/catch vs try/rescue?

Other answers already cover usage of raise vs. throw well. I’ll describe the mechanics of how to handle each exceptional situation using a table: creating | handling with | where y is —————————————————– raise x | rescue y | %RuntimeError{message: x} error(x) | rescue y | %ErlangError{original: x} throw x | catch y | x … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)