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.

ityonemo

ityonemo

Basically everyone (including ecto) uses elixir_uuid. It’s effectively an “anointed package” at this point, though I wish it had typespecs :slight_smile:

aseigo

aseigo

Does it? Looking at its mix.exs I don’t see such a dependency, and ecto/lib/ecot/uuid.ex implements UUID4 all on its own. Also, the uuid package has an order of magnitude more installs according to hex.pm.

That said, I doubt either of them are going away anytime soon.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
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
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New

Other popular topics Top

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
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
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
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement