{"id":37204477,"url":"https://github.com/nibiruchain/collections","last_synced_at":"2026-01-14T23:34:17.227Z","repository":{"id":62113184,"uuid":"557916566","full_name":"NibiruChain/collections","owner":"NibiruChain","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-28T10:26:02.000Z","size":210,"stargazers_count":9,"open_issues_count":7,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-28T13:47:12.018Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NibiruChain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-10-26T14:45:29.000Z","updated_at":"2024-05-20T11:43:26.000Z","dependencies_parsed_at":"2023-12-11T19:29:16.396Z","dependency_job_id":"d876d4a1-20f7-408e-9d87-f67e0d59e3ee","html_url":"https://github.com/NibiruChain/collections","commit_stats":{"total_commits":15,"total_committers":8,"mean_commits":1.875,"dds":0.8,"last_synced_commit":"7689949b8d199a4ddb4133156f05a15e24129679"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/NibiruChain/collections","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibiruChain%2Fcollections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibiruChain%2Fcollections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibiruChain%2Fcollections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibiruChain%2Fcollections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NibiruChain","download_url":"https://codeload.github.com/NibiruChain/collections/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NibiruChain%2Fcollections/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28438746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: 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":[],"created_at":"2026-01-14T23:34:16.705Z","updated_at":"2026-01-14T23:34:17.213Z","avatar_url":"https://github.com/NibiruChain.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Collections\n\nA simplified way to deal with Cosmos-SDK module storage.\n\nCollections has multiple APIs to deal with different storage kinds. It offers complex iteration APIs which support even multi-part keys.\n\nIt's pure golang, no reflection, no protobuf options, only generics.\n\nEach collections API accepts a KeyEncoder and (or) a ValueEncoder.\n\n## Examples\n\nExamples are [here](./examples). Follow them in order.\n\n## Namespaces\n\nEach collection type will expect you to define a namespace, a namespace is a number which ranges from 0 to 255.\nEach collection type (Indexers too), must have a unique namespace in the module.\n\n## KeyEncoders\n\nKeyEncoder teaches to collection how to encode and decode the key used to map the object into the storage.\n\nCollections comes in with a preset of key encoders which guarantee lexographical ordering of keys, more can be added depending on your needs as long as you implement the KeyEncoder interface.\n\n\n# ValueEncoders\n\nValueEncoder teaches the collection type how to convert the object we're storing into bytes, or turning the bytes\ninto the object stored itself.\n\n\n\n## Map\n\nMap is the first storage type which maps keys to object.\nObjects can be of different kinds.\n\nExample:\n\n````go\ntype MyKeeper struct {\n\tBalances collections.Map[sdk.AccAddress, sdk.Coins]\n}\n\nfunc (k MyKeeper) SendCoin(ctx sdk.Context, from, to sdk.AccAddress, coin sdk.Coins) error {\n\tbalance, err := k.Balances.Get(ctx, from)\n\tif err != nil {\n\t\treturn err\n    }\n\t\n\tnewBalance, ok := balance.SafeSub(coin)\n\tif !ok { return fmt.Errorf(\"not enough balance\") }\n\tk.Balances.Insert(ctx, from, newBalance)\n\t...\n}\n````\n\n\n### KeySet\n\nKeySet, as the words says, is a set of keys. It maps no objects but it retains a set of keys.\n\nExample:\n\n```go\ntype MyKeeper struct {\n\tAllowList collections.KeySet[sdk.AccAddress]\n}\n\nfunc (m MyKeeper) IsAllowed(ctx sdk.Context, addr sdk.AccAddress) bool {\n\treturn m.AllowList.Has(ctx, addr)\n}\n\nfunc (m MyKeeper) Allow(ctx sdk.Context, addr sdk.AccAddress) {\n\tm.AllowList.Insert(ctx, addr)\n}\n\nfunc (m MyKeeper) Disallow(ctx sdk.Context, addr sdk.AccAddress) {\n\tm.AllowList.Delete(ctx, addr)\n}\n```\n\n## Item\n\nItem is a collection type which contains only one object, it's usually used for configs, sequences etc.\n\n````go\ntype MyKeeper struct {\n\tConfig collections.Item[Config]\n}\n\nfunc (m MyKeeper) UpdateConfig(ctx sdk.Context, conf config) {\n\tm.Config.Set(ctx, conf)\n}\n\nfunc (m MyKeeper) GetConfig(ctx sdk.Context) (Config, err) {\n\treturn m.Config.Get(ctx)\n}\n````\n\n## Sequence\n\nSequence is a helper type which implements an ever increasing number.\n\n\n## IndexedMap \n\nIndexedMap allows to create complex indexing functionalities around stored objects.\nIt builds on top of a normal collections.Map and uses collections.KeySet to create reference keys\nbetween the primary key and the indexing key.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnibiruchain%2Fcollections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnibiruchain%2Fcollections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnibiruchain%2Fcollections/lists"}