Elixir implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
Find a file
Patrik Stenmark b0180b0619 Rename type option to column_type
Thr reaason for this is that Ecto seems to be handling options
differently when the custom type is used for a `belongs_to` field. For
example if `belongs_to :thing, Thing, type: TypeID` is specified, the
value for `type` will be `TypeIO`, which makes the opts valdiation fail.
Using another name for `type`, makes it possible to both set `type` (The
Ecto type of the field) and `column_type` (The column type in the
database)`.
2024-10-03 09:05:33 +02:00
.github use published release type 2023-07-07 13:31:35 -04:00
lib Rename type option to column_type 2024-10-03 09:05:33 +02:00
priv/spec Support 0.3.0 spec () 2024-04-22 10:00:51 -04:00
scripts Support 0.3.0 spec () 2024-04-22 10:00:51 -04:00
test Jason.Encoder impl () 2023-07-07 14:38:26 -04:00
.formatter.exs mix new 2023-06-29 15:20:23 -04:00
.gitignore Better support for Ecto () 2023-07-16 11:01:51 -04:00
.tool-versions mix new 2023-06-29 15:20:23 -04:00
CHANGELOG.md fix: raise if primary_key: true and no prefix () 2023-07-16 11:36:19 -04:00
CODE_OF_CONDUCT.md Add Code of Conduct and Contributing documentation () 2023-07-06 15:59:55 -04:00
CONTRIBUTING.md Add Code of Conduct and Contributing documentation () 2023-07-06 15:59:55 -04:00
LICENSE add license 2023-06-30 06:49:44 -04:00
mix.exs 1.0.0 2024-08-28 12:19:40 -04:00
mix.lock Jason.Encoder impl () 2023-07-07 14:38:26 -04:00
README.md 1.0.0 2024-08-28 12:19:40 -04:00

TypeID Elixir

CI Hex.pm Documentation

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, "~> 1.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: :uuid}
  @foreign_key_type TypeID

  # ...
end

Underlying types

TypeIDs can be stored as either :string or :uuid. :string will store the entire TypeID including the prefix. :uuid stores only the UUID portion and requires a :uuid or :uuid column.

Default type

The type used can be set globally in the application config.

config :typeid_elixir,
  default_type: :uuid