{"id":21424482,"url":"https://github.com/jinjor/elm-insertable-key","last_synced_at":"2025-03-16T20:42:52.815Z","repository":{"id":62418609,"uuid":"147239152","full_name":"jinjor/elm-insertable-key","owner":"jinjor","description":"Generates a new key between two keys","archived":false,"fork":false,"pushed_at":"2018-09-06T17:10:58.000Z","size":33,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T07:14:14.125Z","etag":null,"topics":["elm","rdb"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/jinjor/elm-insertable-key/latest","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jinjor.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}},"created_at":"2018-09-03T18:18:07.000Z","updated_at":"2018-09-06T17:11:00.000Z","dependencies_parsed_at":"2022-11-01T16:48:50.288Z","dependency_job_id":null,"html_url":"https://github.com/jinjor/elm-insertable-key","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinjor%2Felm-insertable-key","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinjor%2Felm-insertable-key/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinjor%2Felm-insertable-key/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinjor%2Felm-insertable-key/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jinjor","download_url":"https://codeload.github.com/jinjor/elm-insertable-key/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243933375,"owners_count":20370988,"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":["elm","rdb"],"created_at":"2024-11-22T21:22:32.444Z","updated_at":"2025-03-16T20:42:52.780Z","avatar_url":"https://github.com/jinjor.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elm-insertable-key\n\n[![Build Status](https://travis-ci.org/jinjor/elm-insertable-key.svg?branch=master)](https://travis-ci.org/jinjor/elm-insertable-key)\n\nGenerates a new key between two keys.\n\n## What is this?\n\nIf you want to insert new record between B and C,\n\n|id|sort_key|\n|:--|:--|\n|A|1|\n|B|2|\n|C|3|\n|D|4|\n\nThis library gives you a new key `21`.\n\n|id|sort_key|\n|:--|:--|\n|A|1|\n|B|2|\n|E|21|\n|C|3|\n|D|4|\n\nThis can be useful, when you use RDB and change the order without rearranging all of the rows.\n\n## Example\n\n```elm\nimport InsertableKey exposing (Key, after, before, between, init)\n\ngenerateThreeKeys : Maybe ( Key, Key, Key )\ngenerateThreeKeys =\n    let\n        left =\n            init\n    in\n    after left\n        |\u003e Maybe.andThen\n            (\\right -\u003e\n                between left right\n                    |\u003e Maybe.map\n                        (\\center -\u003e\n                            ( left, center, right )\n                        )\n            )\n```\n\n## How it works?\n\n- Each charactor in the keys is one of `0-9A-Za-z` (62 chars), but the last charactor must not be `0`.\n- The first key is `1`.\n- After that, one of the following will be generated:\n  - A key which is *after* the existing key\n  - A key which is *before* the existing key\n  - A key which is *between* the existing two keys in a row\n- It tries to increment the first char, but in case the new key is not smaller than the next one, tries the next char... and so on.\n- i.e.\n  - `between \"1\" \"3\" == Just \"2\"`\n  - `between \"1\" \"2\" == Just \"11\"`\n  - `between \"1\" \"11\" == Just \"101\"`\n  - `after \"1\" == Just \"2\"`\n  - `after \"z\" == Just \"z1\"`\n  - [Others](https://github.com/jinjor/elm-insertable-key/blob/fa3f47692490d77ac603e4f6284e68d4681e2678/tests/Tests.elm#L91-L154)\n\n\n## Help wanted!\n\nThis works well at least *for my use case*, but there should be better algorithm to do this.\n\n- Key may be too long as row increases. The key after `z` is `z1`, and the key after `zz` is `zz1`. This means simply incrementing key until `N` results in the key length `N / 62`. So the length is `16` when we have 1000 rows and `160` when we have 10000. Considering UUID is 36 chars, `N = 2000` would be a good limit.\n- Key may be also too long when continuousely generating key between an integer and the next one, like `11`, `101`, `1001`, `10001` ... `100000000001`. I think this should be fixed if a key is chosen which is placed near the center of two keys.\n\nIf you have some information about this problem, please let me know. Forking and publishing your own is also welcome!\n\n## LICENSE\n\nBSD-3-Clause\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinjor%2Felm-insertable-key","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjinjor%2Felm-insertable-key","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinjor%2Felm-insertable-key/lists"}