eadb269342
* replace shell script with elixir script * update to 0.3.0 spec * update parser to support 0.3.0 spec * use binary_part/3 for elixir 1.11 support * add .exs extension to update_spec script |
||
---|---|---|
.github | ||
lib | ||
priv/spec | ||
scripts | ||
test | ||
.formatter.exs | ||
.gitignore | ||
.tool-versions | ||
CHANGELOG.md | ||
CODE_OF_CONDUCT.md | ||
CONTRIBUTING.md | ||
LICENSE | ||
mix.exs | ||
mix.lock | ||
README.md |
TypeID Elixir
A type-safe, K-sortable, globally unique identifier inspired by Stripe IDs
TypeIDs are a modern, type-safe, globally unique identifier based on the upcoming UUIDv7 standard. They provide a ton of nice properties that make them a great choice as the primary identifiers for your data in a database, APIs, and distributed systems. Read more about TypeIDs in their spec.
Installation
The package can be installed from hex by adding typeid_elixir
to your list of dependencies in mix.exs
:
def deps do
[
{:typeid_elixir, "~> 0.5.0"}
]
end
Spec
The original TypeID spec is defined here.
Usage with Ecto
TypeID
implements the Ecto.ParameterizedType
behaviour so you can use
TypeIDs as fields in your Ecto schemas.
defmodule MyApp.Accounts.User do
use Ecto.Schema
@primary_key {:id, TypeID, autogenerate: true, prefix: "acct", type: :binary_id}
@foreign_key_type TypeID
# ...
end
Underlying types
TypeID
s can be stored as either :string
or :binary_id
. :string
will
store the entire TypeID including the prefix. :binary_id
stores only the
UUID portion and requires a :uuid
or :binary
column.
Default type
The type used can be set globally in the application config.
config :typeid_elixir,
default_type: :binary_id