View Source Ecto.ShortUUID (ecto_shortuuid v0.4.0)
An Ecto type for Short UUID strings.
Summary
Functions
Generates a random ShortUUID string for use in primary keys.
Casts a value to a ShortUUID.
Dumps a ShortUUID or standard UUID to binary format for database storage.
Ecto v3 callback Dictates how the type should be treated inside embeds. https://hexdocs.pm/ecto/Ecto.Type.html#c:embed_as/1
Ecto v3 callback Checks if two terms are semantically equal. https://hexdocs.pm/ecto/Ecto.Type.html#c:equal?/2
Generates a ShortUUID string based on a version 4 (random) UUID.
Loads a binary UUID from the database and converts it to ShortUUID format.
Returns the underlying schema type for the custom type.
Types
@type raw() :: <<_::128>>
A raw binary representation of a UUID.
@type shortuuid() :: binary()
A ShortUUID string.
@type uuid() :: <<_::288>>
A hex-encoded UUID string.
Functions
@spec autogenerate() :: shortuuid()
Generates a random ShortUUID string for use in primary keys.
This is called by Ecto when a record is inserted if the schema has
@primary_key {:id, CustomShortUUIDType, autogenerate: true}
.
Casts a value to a ShortUUID.
Accepts:
- Standard UUID strings (converts them to ShortUUID format)
- ShortUUID strings (validates them)
Returns:
{:ok, shortuuid}
on success:error
on failure
Dumps a ShortUUID or standard UUID to binary format for database storage.
Accepts:
- ShortUUID strings
- Standard UUID strings
Returns:
{:ok, binary_uuid}
on success:error
on failure
@spec embed_as(term()) :: :self
Ecto v3 callback Dictates how the type should be treated inside embeds. https://hexdocs.pm/ecto/Ecto.Type.html#c:embed_as/1
Ecto v3 callback Checks if two terms are semantically equal. https://hexdocs.pm/ecto/Ecto.Type.html#c:equal?/2
@spec generate() :: shortuuid()
Generates a ShortUUID string based on a version 4 (random) UUID.
Loads a binary UUID from the database and converts it to ShortUUID format.
Returns:
{:ok, shortuuid}
on success:error
on failure
Raises an ArgumentError
if given a string UUID instead of binary.
@spec type() :: :uuid
Returns the underlying schema type for the custom type.
For ShortUUID, this is always :uuid
as the data is stored in UUID format
in the database.