ecto_shortuuid v0.1.1 Ecto.ShortUUID View Source

An Ecto type for Short UUID strings.

Link to this section Summary

Types

A raw binary representation of a UUID

A base57 ShortUUID string

A hex-encoded UUID string

Functions

Casts the given input to the custom type

Converts a string representing a ShortUUID or UUID into a binary

Generates a ShortUUID string based on a version 4 (random) UUID

Converts a binary UUID into a ShortUUID string

The Ecto type

Link to this section Types

Link to this type

raw() View Source
raw() :: <<_::128>>

A raw binary representation of a UUID.

Link to this type

shortuuid57() View Source
shortuuid57() :: <<_::176>>

A base57 ShortUUID string.

Link to this type

uuid() View Source
uuid() :: <<_::288>>

A hex-encoded UUID string.

Link to this section Functions

Link to this function

cast(shortuuid) View Source
cast(shortuuid57() | uuid() | any()) :: {:ok, shortuuid57()} | :error

Casts the given input to the custom type.

This callback is called on external input and can return any type, as long as the dump/1 function is able to convert the returned value into an Ecto native type. There are two situations where this callback is called:

  1. When casting values by Ecto.Changeset
  2. When passing arguments to Ecto.Query

When returning {:error, keyword()}, the returned keyword list will be preserved in the changeset errors, similar to Changeset.add_error/4. Passing a :message key, will override the default message. It is not possible to override the :type key.

For {:array, CustomType} or {:map, CustomType} the returned keyword list will be erased and the default error will be shown.

Callback implementation for Ecto.Type.cast/1.

Link to this function

dump(uuid) View Source
dump(shortuuid57() | uuid() | any()) :: {:ok, raw()} | :error

Converts a string representing a ShortUUID or UUID into a binary.

Generates a ShortUUID string based on a version 4 (random) UUID.

Link to this function

load(uuid) View Source
load(binary()) :: {:ok, binary()} | :error

Converts a binary UUID into a ShortUUID string.

The Ecto type.