{"id":32173879,"url":"https://github.com/girishramnani/elixir-ksuid","last_synced_at":"2026-02-21T12:01:28.354Z","repository":{"id":57514295,"uuid":"93783454","full_name":"girishramnani/elixir-ksuid","owner":"girishramnani","description":"K-Sortable Globally Unique IDs for elixir","archived":false,"fork":false,"pushed_at":"2024-02-27T10:31:55.000Z","size":17,"stargazers_count":111,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-02-09T06:21:12.081Z","etag":null,"topics":["elixir"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/girishramnani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-08T19:13:06.000Z","updated_at":"2025-09-05T13:43:06.000Z","dependencies_parsed_at":"2024-02-27T11:53:26.549Z","dependency_job_id":null,"html_url":"https://github.com/girishramnani/elixir-ksuid","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.0714285714285714,"last_synced_commit":"142964075ac8d5e72f1d53ae01c4e34497b1e071"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/girishramnani/elixir-ksuid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/girishramnani%2Felixir-ksuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/girishramnani%2Felixir-ksuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/girishramnani%2Felixir-ksuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/girishramnani%2Felixir-ksuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/girishramnani","download_url":"https://codeload.github.com/girishramnani/elixir-ksuid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/girishramnani%2Felixir-ksuid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29680147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T11:29:27.227Z","status":"ssl_error","status_checked_at":"2026-02-21T11:29:20.292Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir"],"created_at":"2025-10-21T19:00:48.628Z","updated_at":"2026-02-21T12:01:28.337Z","avatar_url":"https://github.com/girishramnani.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ksuid [![Build Status](https://travis-ci.org/girishramnani/elixir-ksuid.svg?branch=master)](https://travis-ci.org/girishramnani/elixir-ksuid)\n\nksuid is a zero dependency Elixir library for generating and parsing KSUIDs.\n\nRead more about ksuid [here](https://segment.com/blog/a-brief-history-of-the-uuid/)\n\n## Installation\n\n```elixir\ndef deps do\n  [{:ksuid, \"~\u003e 0.1.2\"}]\nend\n```\n\n## How To\n\n```elixir\n\niex\u003e Ksuid.generate()\n\"0p9kxW1vWavpdq7VSgbv8piY0nr\"\n\niex\u003e Ksuid.parse(\"0p9kxW1vWavpdq7VSgbv8piY0nr\")\n{\n  :ok,\n  %DateTime{calendar: Calendar.ISO, day: 9, hour: 14, microsecond: {0, 0},\n    minute: 52, month: 6, second: 34, std_offset: 0, time_zone: \"Etc/UTC\",\n    utc_offset: 0, year: 2017, zone_abbr: \"UTC\"},\n  \u003c\u003c166, 90, 80, 117, 89, 88, 196, 168, 113, 163, 157, 217, 224, 51, 151, 227\u003e\u003e\n }\n\n```\n\n## Example Ecto Usage\n\n### Ecto Type\n```elixir\ndefmodule EctoKsuid do\n  @behaviour Ecto.Type\n  # uses string/varchar as storage type.\n  def type, do: :string\n\n  def cast(ksuid) when is_binary(ksuid), do: {:ok, ksuid}\n  def cast(_), do: :error\n\n  @doc \"\"\"\n  Same as `cast/1` but raises `Ecto.CastError` on invalid arguments.\n  \"\"\"\n  def cast!(value) do\n    case cast(value) do\n      {:ok, ksuid} -\u003e ksuid\n      :error -\u003e raise Ecto.CastError, type: __MODULE__, value: value\n    end\n  end\n\n  def load(ksuid), do: {:ok, ksuid}\n  \n  def dump(binary) when is_binary(binary), do: {:ok, binary}\n  def dump(_), do: :error\n\n  # Callback invoked by autogenerate fields - this is all that really matters\n  # just passing around the binary otherwise.\n  @doc false\n  def autogenerate, do: Ksuid.generate()\n\nend\n```\n\n### Usage in a Schema\n`:inserted_at` is a virtual field that can be derived/loaded from the autogenerated `:id`\n\n```elixir\ndefmodule TestSchema do\n  use Ecto.Schema\n\n  @primary_key {:id, EctoKsuid, autogenerate: true}\n  schema \"test\" do\n    field :name, :string\n    field :inserted_at, :utc_datetime, virtual: true\n  end\n\n  def inserted_at(%TestSchema{id: ksuid} = row) do\n     {:ok, time_stamp, _} = Ksuid.parse(ksuid)\n     %TestSchema{row | inserted_at: time_stamp}\n  end\n  \nend\n```\n#### Migration\nCreate `:id` as `:bytea`, and primary key - similary to usage with `:binary_id`\n\n```elixir\n  def change do\n     create table(:test, primary_key: false) do\n      add :id, :string, primary_key: true, size: 26\n      add :name, :text\n     \n    end\n  end\n```\n\n## TODO\n\n- [x] Generate KSUID\n- [x] Parsing KSUIDS\n- [x] Decode BASE62 method\n- [x] Write tests\n- [ ] Write Documentation\n\n\n## Credit\n\n[Segmentio/ksuid](https://github.com/segmentio/ksuid)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgirishramnani%2Felixir-ksuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgirishramnani%2Felixir-ksuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgirishramnani%2Felixir-ksuid/lists"}