Ecto.ULID (helper v1.0.1) View Source

An Ecto type for ULID (Universally Unique Lexicographically Sortable Identifier) bitstring. This format is binary compatible with UUID, but also provides lexicographic sorting capability. The spec for ULID can be found here

Link to this section Summary

Types

ASCII type definition for ULID

t()

The binary type definition for ULID

A combination of binary and ASCII types

Functions

Ecto.Type.autogenerate/0 callback implementation

Ecto.Type.cast/1 callback implementation

Ecto.Type.dump/1 callback implementation

Ecto.Type.embed_as/1 callback implementation

Ecto.Type.equal?/2 callback implementation

Ecto.Type.load/1 callback implementation

Ecto.Type.type/0 callback implementation

Validate the ULID and return true or false. An ULID is valid when it can be converted to a 128 bit string and the significant 48 bits when converted to integer are less then the current unix time in milliseconds

Link to this section Types

Specs

pretty() :: <<_::208>>

ASCII type definition for ULID

Specs

t() :: <<_::128>>

The binary type definition for ULID

Specs

ulid() :: t() | pretty()

A combination of binary and ASCII types

Link to this section Functions

Specs

autogenerate() :: t()

Ecto.Type.autogenerate/0 callback implementation

Specs

cast(ulid()) :: {:ok, t()} | :error

Ecto.Type.cast/1 callback implementation

Specs

dump(ulid()) :: {:ok, t()} | :error

Ecto.Type.dump/1 callback implementation

Specs

embed_as(atom()) :: :self

Ecto.Type.embed_as/1 callback implementation

Examples

iex> embed_as(:any)
:self

Specs

equal?(t1, t2) :: boolean() when t1: ulid(), t2: t1

Ecto.Type.equal?/2 callback implementation

Specs

load(ulid()) :: :error | {:ok, pretty()}

Ecto.Type.load/1 callback implementation

Specs

type() :: :uuid

Ecto.Type.type/0 callback implementation

Examples

iex> type()
:uuid

Specs

valid?(ulid() | :error) :: boolean()

Validate the ULID and return true or false. An ULID is valid when it can be converted to a 128 bit string and the significant 48 bits when converted to integer are less then the current unix time in milliseconds