{"id":18327686,"url":"https://github.com/dario-l/linearkeyallocator","last_synced_at":"2026-05-02T04:31:49.155Z","repository":{"id":73986310,"uuid":"225896079","full_name":"dario-l/LinearKeyAllocator","owner":"dario-l","description":"Linear key allocator for MS Sql Server","archived":false,"fork":false,"pushed_at":"2024-01-17T08:41:09.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T10:14:55.042Z","etag":null,"topics":["chunk","database","generator","hilo","identifier","key-allocator","linear","rdbms"],"latest_commit_sha":null,"homepage":"","language":"C#","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/dario-l.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":"2019-12-04T15:16:22.000Z","updated_at":"2024-01-17T08:41:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"b9abb4e4-8ad3-41f0-b6ff-84a6586b5212","html_url":"https://github.com/dario-l/LinearKeyAllocator","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/dario-l%2FLinearKeyAllocator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-l%2FLinearKeyAllocator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-l%2FLinearKeyAllocator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dario-l%2FLinearKeyAllocator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dario-l","download_url":"https://codeload.github.com/dario-l/LinearKeyAllocator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248068523,"owners_count":21042507,"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":["chunk","database","generator","hilo","identifier","key-allocator","linear","rdbms"],"created_at":"2024-11-05T19:12:00.665Z","updated_at":"2026-05-02T04:31:44.122Z","avatar_url":"https://github.com/dario-l.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LinearKeyAllocator\n![LinearKeyAllocator](https://img.shields.io/nuget/v/LinearKeyAllocator)\n\nLinearKeyAllocator allows to generate incremental keys (int, long) based\non last seed value stored in database.\n\nWorks likes the HiLo algorithm (from NHibernate) but better becouse\ndo not create big holes when application restarts.\n\nIt aims to be a tool for generating database keys without having to\nrely on RDBMS identity column.\n\nLinearKeyAllocator works like database 'Sequence'.\nIt means does not attach to any ambient transaction.\n\nOnce generated chunk of keys are available until application restarts.\nAfter restart it will start from last saved max value.\n\n\n**Why is it better than HiLo?**\n\nSet LinearKeyAllocator seedSize to 20.\n\n```\nLinearKeyAllocator          HiLo\n...\n100                         65536\n101                         65537\n102                         65538\n... application restart\n120                         131072\n121                         131073\n122                         131073\n... application restart\n140                         196608\n```\n\n**Example**\n``` c#\nclass Program\n{\n    private static string cnn =\n        \"Server=(local); Database=Test; Trusted_Connection=True; MultipleActiveResultSets=true\";\n\n    static async Task Main(string[] args)\n    {\n        var generator = await new KeyAllocator(cnn).Initialize();\n\n        const string type1 = \"Type1\";\n        const string type2 = \"Type2\";\n\n        using var scope =\n            new TransactionScope(\n                TransactionScopeOption.Required,\n                TransactionScopeAsyncFlowOption.Enabled);\n\n        for (var i = 0; i \u003c 5000; i++)\n        {\n            var key = (i % 2 == 0) ? type1 : type2;\n\n            var value = await generator.GenerateInt32(key);\n            Console.WriteLine(\"{0}: {1}\", key, value);\n        }\n\n        scope.Complete();\n\n        Console.WriteLine(\"Press any key...\");\n        Console.ReadKey();\n    }\n}\n```\n\n**Sql Script**\n``` SQL\nCREATE TABLE [dbo].[LinearKeyAllocator](\n    [Key] [varchar](255) NOT NULL,\n    [NextMax] [bigint] NOT NULL,\n    CONSTRAINT [PK_LinearKeyAllocator] PRIMARY KEY CLUSTERED ([Key] ASC)\n) ON [PRIMARY]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdario-l%2Flinearkeyallocator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdario-l%2Flinearkeyallocator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdario-l%2Flinearkeyallocator/lists"}