View Source LibEcto.KsuidType (lib_ecto v0.3.8)

types for ksuid uses string/varchar as storage type.

Example

defmodule TestSchema do
  use Ecto.Schema
  alias LibEcto.KsuidType

  @primary_key {:id, KsuidType, autogenerate: true}
  schema "test" do
    field :name, :string
    field :inserted_at, :utc_datetime, virtual: true
  end

  def inserted_at(%TestSchema{id: ksuid} = row) do
     {:ok, time_stamp, _} = LibEcto.Ksuid.parse(ksuid)
     %TestSchema{row | inserted_at: time_stamp}
  end
end

BE CAREFUL!!!!

If you are using ksuid as your primary key, it is important to declare the id type as binary when creating your table. Failing to do so may result in problems with sorting and comparison.

CREATE TABLE test_table (
  id VARCHAR(20) BINARY PRIMARY KEY,
  name VARCHAR(50)
);

Summary

Functions

Callback implementation for Ecto.Type.cast/1.

Same as cast/1 but raises Ecto.CastError on invalid arguments.

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

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

Callback implementation for Ecto.Type.load/1.

Callback implementation for Ecto.Type.type/0.

Functions

Callback implementation for Ecto.Type.cast/1.

Same as cast/1 but raises Ecto.CastError on invalid arguments.

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

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

Callback implementation for Ecto.Type.load/1.

Callback implementation for Ecto.Type.type/0.