UUIDv7.Type (UUIDv7 v0.6.0)

View Source

Ecto type for UUIDv7.

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.

Types

raw()

@type raw() :: UUIDv7.raw()

t()

@type t() :: UUIDv7.t()

Ecto.Type Functions

cast(uuid)

@spec cast(t() | raw() | any()) :: {:ok, t()} | :error

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

cast!(uuid)

@spec cast!(t() | raw() | any()) :: t()

Same as cast/1 but raises Ecto.CastError on invalid arguments.

dump(uuid_string)

@spec dump(uuid_string :: t() | any()) :: {:ok, raw()} | :error

Converts a string representing a UUID into a raw binary.

dump!(uuid)

@spec dump!(t() | any()) :: raw()

Same as dump/1 but raises Ecto.ArgumentError on invalid arguments.

embed_as(_)

Callback implementation for Ecto.Type.embed_as/1.

equal?(term1, term2)

Callback implementation for Ecto.Type.equal?/2.

load(raw_uuid)

@spec load(raw() | any()) :: {:ok, t()} | :error

Converts a binary UUID into a string.

load!(value)

@spec load!(raw() | any()) :: t()

Same as load/1 but raises Ecto.ArgumentError on invalid arguments.