Search documentation of ash

# View Source Ash.UUIDv7 (ash v3.4.30)

Helpers for working with UUIDs version 7.

RFC 9562

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

## Types

raw()

A raw binary representation of a UUID.

t()

A hex-encoded UUID string.

## Functions

bingenerate()

Generates a version 7 UUID in the binary format.

decode(raw_uuid)

Decode a string representation of a UUID to the raw binary version.

encode(hex_uuid)

Encode a raw UUID to the string representation.

extract_timestamp(uuid)

Extract the millisecond timestamp from the UUID.

generate()

Generates a version 7 UUID using submilliseconds for increased clock precision.

# Types

Link to this type

# raw()

View Source

    @type raw() :: <<_::128>>

A raw binary representation of a UUID.

Link to this type

# t()

View Source

    @type t() :: <<_::288>>

A hex-encoded UUID string.

# Functions

Link to this function

# bingenerate()

View Source

    @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>>

Link to this function

# decode(raw_uuid)

View Source

    @spec decode(t() | raw()) :: raw() | :error

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>>

Link to this function

# encode(hex_uuid)

View Source

    @spec encode(t() | raw()) :: t() | :error

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"

Link to this function

# extract_timestamp(uuid)

View Source

    @spec extract_timestamp(t() | raw()) :: integer()

Extract the millisecond timestamp from the UUID.

## Example

    iex> UUIDv7.extract_timestamp("018ecb40-c457-73e6-a400-000398daddd9")
    1712807003223

Link to this function

# generate()

View Source

    @spec generate() :: t()

Generates a version 7 UUID using submilliseconds for increased clock precision.

## Example

    iex> UUIDv7.generate()
    "018e90d8-06e8-7f9f-bfd7-6730ba98a51b"