{"id":24564662,"url":"https://github.com/pixelbend/typeid-pg","last_synced_at":"2025-03-17T01:16:49.873Z","repository":{"id":239959651,"uuid":"801100656","full_name":"pixelbend/typeid-pg","owner":"pixelbend","description":"A pure plgsql TypeId generation implementation for PostgreSQL","archived":false,"fork":false,"pushed_at":"2025-02-24T00:18:11.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-24T01:23:50.115Z","etag":null,"topics":["k-sortable","postgres","typeid","typesafe","ulid"],"latest_commit_sha":null,"homepage":"","language":"PLpgSQL","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/pixelbend.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":"2024-05-15T15:36:53.000Z","updated_at":"2025-02-24T00:18:14.000Z","dependencies_parsed_at":"2024-05-16T04:46:05.171Z","dependency_job_id":"184d3847-968f-4931-9f62-70104e7e1bab","html_url":"https://github.com/pixelbend/typeid-pg","commit_stats":null,"previous_names":["arkamfahry/pg-typeid","arkamfahry/typeid-psql","driftdev/typeid-pg","teapartydev/typeid-pg","codefrantic/typeid-pg","pixelbend/typeid-pg"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Ftypeid-pg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Ftypeid-pg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Ftypeid-pg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixelbend%2Ftypeid-pg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pixelbend","download_url":"https://codeload.github.com/pixelbend/typeid-pg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243955801,"owners_count":20374373,"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":["k-sortable","postgres","typeid","typesafe","ulid"],"created_at":"2025-01-23T11:14:45.861Z","updated_at":"2025-03-17T01:16:49.853Z","avatar_url":"https://github.com/pixelbend.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeId Pg\n\n## An Implementation of TypeId for Postgres\n\nTypeId is a type-safe, globally unique identifier format inspired by Stripe's IDs, designed to be sortable, unique and type-safe.\n\nThis implementation of TypeId does some modification to the base TypeId specification by replacing the random UUID part of the TypeId in favor of a sortable ULID\n\nThis implement of TypeId consists of two parts a `Type` prefix and a `ULID` suffix, separated by an underscore.\n\n- ```pseudo\n  user_01HXYG96MV7WS0E2KW4ZCGP3KZ\n  └──┘ └────────────────────────┘\n  Type          ULID\n  ```\n\n- **Type Prefix**\n  - The type prefix is a string of up to 63 characters in lowercase snake_case ASCII (a-z and underscore). It indicates the type of entity the TypeId represents (e.g., user, post, etc.). This helps prevent accidental misuse of IDs and aids in understanding the entity type.\n- **ULID Suffix**\n  - Following the underscore is a 26-character string that represents a ULID. This part ensures the TypeId's global uniqueness and this also makes TypeId's sortable.\n\nThis implementations TypeId offers a modern and efficient way to handle globally unique identifiers in a type-safe manner, with enhanced sorting capabilities.\n\n## Usage of Pg-TypeId\n\nOnce you've installed the TypeID types and functions from `typeid.sql` in your Postgres instance, you can use it as follows.\n\n- Generating TypeId\n\n  - ```sql\n    -- Generate a TypeId\n    select gen_typeid('user') \n    -- Result: user_01HXZF9VT3ANNTRE39FBXDGHBM \n    ```\n\n- Validating TypeId\n\n  - ```sql\n    -- If TypeId is valid\n    select check_typeid('user_01HXZF9VT3ANNTRE39FBXDGHBM', 'user') \n    -- Result: true\n\n    -- If TypeId is invalid\n    select check_typeid('01HXZF9VT3ANNTRE39FBXDGHBM', 'user')\n    -- Result: false\n    ```\n\n- Defining TypeId\n\n  - ```sql\n    -- Defining a users table with TypeId of type `user` as primary key\n    create table users (\n      -- The id is a TypeId of with the type of `user`.   \n      -- The id also has a default constraint of `gen_typeid` to autogenerated TypeId with with the correct type of `user`. \n      -- The id also has a check constraint of `check_typeid` to check if it's a valid TypeId and has the correct type of `user`.\n      id varchar(256) default gen_typeid('user') not null check(check_typeid(id, 'user')) primary key,\n      name varchar(256) not null,\n      email varchar(256) not null,\n      created_at timestamptz default now() not null,\n      updated_at timestamptz\n    );\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelbend%2Ftypeid-pg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpixelbend%2Ftypeid-pg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixelbend%2Ftypeid-pg/lists"}