{"id":20015458,"url":"https://github.com/ryanwinchester/uuidv7","last_synced_at":"2025-04-06T18:13:27.127Z","repository":{"id":224828271,"uuid":"764353985","full_name":"ryanwinchester/uuidv7","owner":"ryanwinchester","description":"UUIDv7 for Elixir (and Ecto)","archived":false,"fork":false,"pushed_at":"2025-03-01T00:11:52.000Z","size":65,"stargazers_count":45,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T17:08:14.980Z","etag":null,"topics":["ecto","uuidv7"],"latest_commit_sha":null,"homepage":"","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/ryanwinchester.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"ryanwinchester"}},"created_at":"2024-02-27T23:26:24.000Z","updated_at":"2025-03-22T13:31:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"4a9c6428-88c7-4c13-a98c-43a07503f31c","html_url":"https://github.com/ryanwinchester/uuidv7","commit_stats":null,"previous_names":["ryanwinchester/uuidv7"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanwinchester%2Fuuidv7","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanwinchester%2Fuuidv7/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanwinchester%2Fuuidv7/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanwinchester%2Fuuidv7/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanwinchester","download_url":"https://codeload.github.com/ryanwinchester/uuidv7/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526753,"owners_count":20953143,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["ecto","uuidv7"],"created_at":"2024-11-13T07:46:11.510Z","updated_at":"2025-04-06T18:13:27.106Z","avatar_url":"https://github.com/ryanwinchester.png","language":"Elixir","funding_links":["https://github.com/sponsors/ryanwinchester"],"categories":[],"sub_categories":[],"readme":"# UUIDv7\n\n[![CI](https://github.com/ryanwinchester/uuidv7/actions/workflows/ci.yml/badge.svg)](https://github.com/ryanwinchester/uuidv7/actions/workflows/ci.yml)\n[![Hex.pm](https://img.shields.io/hexpm/v/uuid_v7)](https://hex.pm/packages/uuid_v7)\n[![Hex.pm](https://img.shields.io/hexpm/dt/uuid_v7)](https://hex.pm/packages/uuid_v7)\n[![Hex.pm](https://img.shields.io/hexpm/l/uuid_v7)](https://github.com/ryanwinchester/uuidv7/blob/main/LICENSE)\n\nUUIDv7 for Elixir and (optionally) Ecto, using always-increasing clock-precision for monotonicity.\n\nUses suggestions described in **[Section 6.2](https://www.rfc-editor.org/rfc/rfc9562#name-monotonicity-and-counters)** from [RFC 9562](https://www.rfc-editor.org/rfc/rfc9562)\nto add additional sort precision to a version 7 UUID.\n\n## When should I use this package?\n\n- You want sequential, time-based, ordered IDs (per-node).\n- You are willing to trade a small amount of raw performance for these\n  guarantees.\n\nNOTE: In this library, sequential UUIDs and ordering are more important than time precision and performance.\nWe take a slight hit in both of those areas to ensure that the UUIDs are in order. For example, in the case of a\nbackwards time leap, or even concurrent requests at the same time, we continue with the previously used\ntimestamp and increment the clock precision by a minimum step.\n\n## When should I not use this package?\n\n- You don't care about sort/order precision beyond milliseconds.\n\nThere are other UUID packages, that only have millisecond precision, for example:\n\n- [martinthenth/uuidv7](https://github.com/martinthenth/uuidv7)\n- [bitwalker/uniq](https://github.com/bitwalker/uniq)\n\n## Installation\n\nThe package can be installed by adding `uuid_v7` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:uuid_v7, \"~\u003e 0.6.0\"}\n  ]\nend\n```\n\n## Usage\n\n```elixir\niex\u003e UUIDv7.generate()\n\"018e90d8-06e8-7f9f-bfd7-6730ba98a51b\"\n\niex\u003e UUIDv7.bingenerate()\n\u003c\u003c1, 142, 144, 216, 124, 16, 127, 196, 158, 92, 92, 74, 83, 46, 116, 173\u003e\u003e\n```\n\n## Usage with Ecto\n\nUse this the same way you would use `Ecto.UUID`. For example:\n\n```elixir\ndefmodule MyApp.Blog.Post do\n  use Ecto.Schema\n\n  @primary_key {:id, UUIDv7.Type, autogenerate: true}\n\n  @foreign_key_type UUIDv7.Type\n\n  schema \"blog_posts\" do\n    field :text, :string\n    # etc.\n  end\nend\n```\n\nTo use UUIDs for everything in your migrations, it's easiest to just add that as the\ndefault type in your config. e.g.:\n\n```elixir\n# config/config.exs\nconfig :app, App.Repo,\n  migration_primary_key: [type: :binary_id],\n  migration_foreign_key: [type: :binary_id]\n```\n\nIf you need to generate UUIDs in migrations (e.g. inserting or seeding data),\nthen also add this to your Repo config as well:\n\n```elixir\n# config/config.exs\nconfig :app, App.Repo,\n  start_apps_before_migration: [:uuid_v7]\n```\n\n## Benchmarks\n\nRun benchmarks with\n\n```\nMIX_ENV=bench mix run bench/filename.exs\n```\n\nWhere `filename.exs` is the name of one of the benchmark files in the `bench` directory.\n\n### Compared to `Uniq.UUID`\n\n(which has no extra clock precision, only millisecond precision.)\n\n#### String:\n\n```\nName                     ips        average  deviation         median         99th %\nuniq v7 string        2.13 M      468.64 ns  ±4155.60%         417 ns         584 ns\nuuid_v7 string        1.98 M      504.57 ns  ±3338.92%         458 ns         667 ns\n\nComparison:\nuniq v7 string        2.13 M\nuuid_v7 string        1.98 M - 1.08x slower +35.93 ns\n```\n\n#### Raw (binary):\n\n```\nName                  ips        average  deviation         median         99th %\nuniq v7 raw        3.14 M      318.58 ns  ±8234.89%         250 ns         417 ns\nuuid_v7 raw        2.85 M      351.26 ns  ±4999.60%         292 ns         459 ns\n\nComparison:\nuniq v7 raw        3.14 M\nuuid_v7 raw        2.85 M - 1.10x slower +32.69 ns\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanwinchester%2Fuuidv7","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanwinchester%2Fuuidv7","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanwinchester%2Fuuidv7/lists"}