Sunbake.Snowflake (Sunbake v0.2.1) View Source

Snowflakes

Link to this section Summary

Functions

Cast the integer to its snowflake representation.

Banged version of cast/1.

Dumps a string version of the snowflake

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Convers an elxiir %DateTime{} into its snowflake form.

Loads the underlying type into the snowflake type

Callback implementation for Ecto.Type.type/0.

Link to this section Functions

Cast the integer to its snowflake representation.

## Examples

  iex> Sunbake.cast(381887113391505410)
  {:ok, 381887113391505410}

  iex> Sunbake.cast("bad_value")
  :error

Banged version of cast/1.

Dumps a string version of the snowflake

Examples

iex> Sunbake.dump(381887113391505410)
{:ok, "381887113391505410"}

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Convers an elxiir %DateTime{} into its snowflake form.

Obviously this does not include the non time components of the snowflake. But it does allow you to order a datetime with snowflakes.

## Examples

  iex> DateTime.now!("Etc/UTC")
  ...> Sunbake.from_datetime()
  "381887113391505410"
Link to this function

from_datetime!(datetime)

View Source

Specs

from_datetime!(DateTime.t()) :: nil | integer()

Banged version of from_datetime/1

Link to this macro

is_snowflake(term)

View Source (macro)

Loads the underlying type into the snowflake type

Examples

iex> Sunbake.load(381887113391505410)
{:ok, 381887113391505410}

Opposite of from_datetime/1

Callback implementation for Ecto.Type.type/0.