View Source UUIDv7 (uuidv7 v1.0.0)
A UUID v7 implementation and Ecto.Type
for Elixir.
The RFC for the version 7 UUID: RFC 9562.
This library includes an Ecto.Type
to (auto-)generate version 7 UUIDs in Ecto.Schema
and beyond.
Installation
The package can be installed by adding uuidv7
to your list of dependencies in mix.exs
:
def deps do
[{:uuidv7, "~> 1.0"}]
end
Usage
In your database schema, change primary key attribute from :binary_id
to UUIDv7
:
def MyApp.Schemas.User do
@primary_key {:id, UUIDv7, autogenerate: true}
end
Summary
Functions
Generates a version 7 UUID in the binary format.
Generates a version 7 UUID in the binary format based on the timestamp (ms).
Callback implementation for Ecto.Type.cast/1
.
Callback implementation for Ecto.Type.dump/1
.
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
Generates a version 7 UUID.
Generates a version 7 UUID based on the timestamp (ms).
Callback implementation for Ecto.Type.load/1
.
Extracts the timestamp (ms) from the version 7 UUID.
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.
@spec bingenerate(non_neg_integer()) :: raw()
Generates a version 7 UUID in the binary format based on the timestamp (ms).
Callback implementation for Ecto.Type.cast/1
.
See Ecto.UUID.cast!/1
.
Callback implementation for Ecto.Type.dump/1
.
See Ecto.UUID.dump!/1
.
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
@spec generate() :: t()
Generates a version 7 UUID.
@spec generate(non_neg_integer()) :: t()
Generates a version 7 UUID based on the timestamp (ms).
Callback implementation for Ecto.Type.load/1
.
See Ecto.UUID.load!/1
.
@spec timestamp(t() | raw()) :: non_neg_integer()
Extracts the timestamp (ms) from the version 7 UUID.