View Source UUIDv7 (uuid_v7 v0.2.1)
UUIDv7 for Elixir (and Ecto).
Summary
Functions
Generates a version 7 UUID in the binary format.
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
.
Generates a version 7 UUID from an existing microsecond timestamp.
Generates a version 7 UUID using microseconds for increased clock precision.
Converts a binary UUID into a string.
Same as load/1
but raises Ecto.ArgumentError
on invalid arguments.
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.
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
.
@spec from_timestamp(pos_integer() | DateTime.t()) :: raw()
Generates a version 7 UUID from an existing microsecond timestamp.
@spec generate() :: t()
Generates a version 7 UUID using microseconds for increased clock precision.
Converts a binary UUID into a string.
Same as load/1
but raises Ecto.ArgumentError
on invalid arguments.