View Source Ash.UUIDv7 (ash v3.4.42)
Helpers for working with UUIDs version 7.
Used for generating UUIDs version 7 with increased clock precision for better monotonicity, as described by method 3 of the [Section 6.2](https://www.rfc-editor.org/rfc/rfc9562#name-monotonicity-and-counters
Inspired by the work of Ryan Winchester on uuidv7
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
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.
Functions
@spec bingenerate() :: raw()
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"