View Source Ecto.ULID (Ecto.ULID v1.0.2)
An Ecto type for ULID strings.
Summary
Functions
Generates a binary ULID.
Casts a string to ULID.
Same as cast/1
, but raises Ecto.CastError
on invalid arguments.
Converts a Crockford Base32 encoded ULID into a binary.
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
Generates a Crockford Base32 encoded ULID.
Converts a binary ULID into a Crockford Base32 encoded string.
The underlying schema type (:uuid
).
Types
@type t() :: <<_::208>>
A hex-encoded ULID string.
Functions
Generates a binary ULID.
Optionally takes a Unix timestamp with millisecond precision as an argument. If no argument is passed, the current time is used as a base for the ULID.
Examples
iex> Ecto.ULID.bingenerate()
<<1, 127, 29, 107, 117, 125, 183, 154, 147, 224, 191, 135, 161, 183, 2, 52>>
iex> Ecto.ULID.bingenerate(1402899630000)
<<1, 70, 163, 85, 135, 176, 12, 219, 112, 32, 157, 209, 98, 152, 55, 37>>
Casts a string to ULID.
Example
iex> Ecto.ULID.cast("018THNB1XG1KDQ084XT5H9GDS5")
{:ok, "018THNB1XG1KDQ084XT5H9GDS5"}
iex> Ecto.ULID.cast("abc")
:error
Same as cast/1
, but raises Ecto.CastError
on invalid arguments.
Example
iex> Ecto.ULID.cast!("018THNB1XG1KDQ084XT5H9GDS5")
"018THNB1XG1KDQ084XT5H9GDS5"
iex> Ecto.ULID.cast!("abc")
** (Ecto.CastError) cannot cast "abc" to Ecto.ULID
Converts a Crockford Base32 encoded ULID into a binary.
Example
iex> Ecto.ULID.dump("018THNB1XG1KDQ084XT5H9GDS5")
{:ok, <<1, 70, 163, 85, 135, 176, 12, 219, 112, 32, 157, 209, 98, 152, 55, 37>>}
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
Generates a Crockford Base32 encoded ULID.
Optionally takes a Unix timestamp with millisecond precision as an argument. If no argument is passed, the current time is used as a base for the ULID.
Examples
iex> Ecto.ULID.generate()
"01FWEPCVGGMQQ0YTKS7BYFQH46"
iex> Ecto.ULID.generate(1402899630000)
"018THNB1XGQZ7T929PD126SM3Z"
Converts a binary ULID into a Crockford Base32 encoded string.
Example
iex> Ecto.ULID.load(<<1, 70, 163, 85, 135, 176, 12, 219, 112, 32, 157, 209, 98, 152, 55, 37>>)
{:ok, "018THNB1XG1KDQ084XT5H9GDS5"}
The underlying schema type (:uuid
).