jeramyRR

jeramyRR

Is there a native way to create a guid/uuid in Elixir?

I’ve been searching for how to create a GUID / UUID in Elixir without needing to bring in a dependency, but I can’t seem to find any docs on it other than using the uuid library. It seems to me that using GUIDs are a fairly common place practice in many many different types of applications and other languages provide the ability to create them in their standard libraries. Am I missing something in my searches for a way to do this without a library?

Most Liked

aseigo

aseigo

If you already depend on Ecto, you can call Ecto.UUID.generate for a UUID4 and get UUIDs without any further deps.

As others have noted, though, Elixir libraries tend to be pretty reliable even when not touched for a long while. This is a very nice benefit of Elixir-the-language being considered “complete” and a strong resistance to adding everything possible to standard library (e.g. UUIDs :wink: ) → the std library has the core tools (as it should) with most everything else in (usually sensibly chunked) libraries, even “very common” things like JSON or UUIDs. As such, things don’t break underneath libraries much at all, and as many libraries have pretty thin dependency chains of their own, this lends a good amount of stability that makes pulling in useful deps pretty low risk.

jeramyRR

jeramyRR

I don’t mind using libraries for things at all, but it seems like relying on a library for something that’s a standard thing in the industry is prone to introducing a problem later. If something in the language changes later and that library isn’t compatible and not updated often then it can lead to issues.

derek-zhou

derek-zhou

If you don’t care much about the format, you can use an erlang ref:

iex(2)> to_string(:erlang.ref_to_list(:erlang.make_ref()))
"#Ref<0.3277125387.4011851777.221466>"

See the doc:

Returns a unique reference. The reference is unique among connected nodes.

Last Post!

ityonemo

ityonemo

Elixir_uuid package is the uuid package renamed to prevent collision with the erlang uuid package when hex.pm started to become the package manager for erlang. You should use elixir_uuid moving forward.

I Stand corrected with ecto. I could swear it was the case though, ha.

Where Next?

Popular in Questions Top

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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement