ShortUUID

Encode and decode UUIDs into a shorter Base58 representation.

iex> ShortUUID.encode("64d7280f-736a-4ffa-b9c0-383f43486d0b")
{:ok, "DTEETeS5R2XxjrVTZxXoJS"}

iex> ShortUUID.decode("DTEETeS5R2XxjrVTZxXoJS")
{:ok, "64d7280f-736a-4ffa-b9c0-383f43486d0b"}

Prefixed IDs (Ecto)

With Ecto installed, ShortUUID.Prefixed provides Stripe-style prefixed IDs as an Ecto parameterized type. UUIDs are stored as-is in the database, prefixed ShortUUIDs are used in your application:

defmodule MyApp.User do
  use ShortUUID.Prefixed.Schema, prefix: "usr"

  schema "users" do
  end
end

user = Repo.get!(User, "usr_F6tzXELwufrXBFtFTKsUvc")
user.id #=> "usr_F6tzXELwufrXBFtFTKsUvc"

See ShortUUID.Prefixed docs for helpers and manual schema setup.

Installation

def deps do
  [
    {:short_uuid, "~> 3.0"}
  ]
end

License

MIT