https://github.com/sloanelybutsurely/typeid-elixir
Elixir implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
https://github.com/sloanelybutsurely/typeid-elixir
base32 crockford-base32 database ecto elixir primary-key typeid uuid uuid7 uuidv7
Last synced: 10 months ago
JSON representation
Elixir implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
- Host: GitHub
- URL: https://github.com/sloanelybutsurely/typeid-elixir
- Owner: sloanelybutsurely
- License: mit
- Created: 2023-06-29T19:21:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-13T14:20:35.000Z (about 1 year ago)
- Last Synced: 2025-03-29T01:02:30.094Z (10 months ago)
- Topics: base32, crockford-base32, database, ecto, elixir, primary-key, typeid, uuid, uuid7, uuidv7
- Language: Elixir
- Homepage:
- Size: 63.5 KB
- Stars: 65
- Watchers: 2
- Forks: 10
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# TypeID Elixir
[](https://github.com/sloanelybutsurely/typeid-elixir/actions/workflows/ci.yaml) [](https://hex.pm/packages/typeid_elixir) [](https://hexdocs.pm/typeid_elixir)
### A type-safe, K-sortable, globally unique identifier inspired by Stripe IDs
[TypeIDs](https://github.com/jetpack-io/typeid) 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](https://hex.pm/packages/typeid_elixir) by adding `typeid_elixir` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:typeid_elixir, "~> 1.0"}
]
end
```
## Spec
The original TypeID spec is defined [here](https://github.com/jetpack-io/typeid).
## Usage with Ecto
`TypeID` implements the `Ecto.ParameterizedType` behaviour so you can use
TypeIDs as fields in your Ecto schemas.
```elixir
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
`TypeID`s 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.
```elixir
config :typeid_elixir,
default_type: :uuid
```