View Source UUIDv7 (UUIDv7 v0.4.3)
UUIDv7 for Elixir.
Used for generating version 7 UUIDs using submillisecond clock precision.
Includes Ecto.Type
implementations.
Examples
iex> UUIDv7.generate()
"018e90d8-06e8-7f9f-bfd7-6730ba98a51b"
iex> UUIDv7.bingenerate()
<<1, 142, 144, 216, 6, 232, 127, 159, 191, 215, 103, 48, 186, 152, 165, 27>>
Summary
Ecto.Type Functions
Casts either a string in the canonical, human-readable UUID format or a 16-byte binary to a UUID in its canonical, human-readable UUID format.
Same as cast/1
but raises Ecto.CastError
on invalid arguments.
Converts a string representing a UUID into a raw binary.
Same as dump/1
but raises Ecto.ArgumentError
on invalid arguments.
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
Converts a binary UUID into a string.
Same as load/1
but raises Ecto.ArgumentError
on invalid arguments.
Functions
Generates a version 7 UUID in the binary format.
Decode a string representation of a UUID to the raw binary version.
Encode a raw UUID to the string representation.
Extract the millisecond timestamp from the UUID.
Generates a version 7 UUID using submilliseconds for increased clock precision.
Types
@type raw() :: <<_::128>>
A raw binary representation of a UUID.
@type t() :: <<_::288>>
A hex-encoded UUID string.
Ecto.Type Functions
Casts either a string in the canonical, human-readable UUID format or a 16-byte binary to a UUID in its canonical, human-readable UUID format.
If uuid
is neither of these, :error
will be returned.
Since both binaries and strings are represent as binaries, this means some strings you may not expect are actually also valid UUIDs in their binary form and so will be casted into their string form.
Examples
iex> raw = <<1, 141, 236, 237, 26, 200, 116, 82, 179, 112, 220, 56, 9, 179, 208, 93>>
iex> UUIDv7.cast(raw)
{:ok, "018deced-1ac8-7452-b370-dc3809b3d05d"}
iex> UUIDv7.cast("018deced-1ac8-7452-b370-dc3809b3d05d")
{:ok, "018deced-1ac8-7452-b370-dc3809b3d05d"}
iex> UUIDv7.cast("warehouse worker")
{:ok, "77617265-686f-7573-6520-776f726b6572"}
Same as cast/1
but raises Ecto.CastError
on invalid arguments.
Converts a string representing a UUID into a raw binary.
Same as dump/1
but raises Ecto.ArgumentError
on invalid arguments.
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
Converts a binary UUID into a string.
Same as load/1
but raises Ecto.ArgumentError
on invalid arguments.
Functions
Generates a version 7 UUID in the binary format.
Example
iex> UUIDv7.bingenerate()
<<1, 142, 144, 216, 6, 232, 127, 159, 191, 215, 103, 48, 186, 152, 165, 27>>
Decode a string representation of a UUID to the raw binary version.
Example
iex> UUIDv7.decode("018e90d8-06e8-7f9f-bfd7-6730ba98a51b")
<<1, 142, 144, 216, 6, 232, 127, 159, 191, 215, 103, 48, 186, 152, 165, 27>>
Encode a raw UUID to the string representation.
Example
iex> UUIDv7.encode(<<1, 142, 144, 216, 6, 232, 127, 159, 191, 215, 103, 48, 186, 152, 165, 27>>)
"018e90d8-06e8-7f9f-bfd7-6730ba98a51b"
Extract the millisecond timestamp from the UUID.
Example
iex> UUIDv7.extract_timestamp("018ecb40-c457-73e6-a400-000398daddd9")
1712807003223
@spec generate() :: t()
Generates a version 7 UUID using submilliseconds for increased clock precision.
Example
iex> UUIDv7.generate()
"018e90d8-06e8-7f9f-bfd7-6730ba98a51b"