{"id":24667465,"url":"https://github.com/rlshukhov/generichold","last_synced_at":"2025-03-21T12:16:14.997Z","repository":{"id":273956450,"uuid":"921431202","full_name":"rlshukhov/generichold","owner":"rlshukhov","description":"GenericHold is BadgerHold extension provided simplest, generics-powered, type-safe API","archived":false,"fork":false,"pushed_at":"2025-01-24T00:54:37.000Z","size":1,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-24T01:23:05.099Z","etag":null,"topics":["badger","badgerdb","badgerhold","generics","generics-in-golang","go","golang","golang-library","golang-package","nosql","nosql-database"],"latest_commit_sha":null,"homepage":"","language":"Go","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/rlshukhov.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":"2025-01-23T23:49:46.000Z","updated_at":"2025-01-24T00:51:30.000Z","dependencies_parsed_at":"2025-01-24T01:23:16.229Z","dependency_job_id":"5e33b8f1-4c5e-4e69-a7c7-5bbd304f7be7","html_url":"https://github.com/rlshukhov/generichold","commit_stats":null,"previous_names":["rlshukhov/generichold"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlshukhov%2Fgenerichold","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlshukhov%2Fgenerichold/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlshukhov%2Fgenerichold/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rlshukhov%2Fgenerichold/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rlshukhov","download_url":"https://codeload.github.com/rlshukhov/generichold/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244795519,"owners_count":20511521,"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":["badger","badgerdb","badgerhold","generics","generics-in-golang","go","golang","golang-library","golang-package","nosql","nosql-database"],"created_at":"2025-01-26T08:17:15.301Z","updated_at":"2025-03-21T12:16:14.953Z","avatar_url":"https://github.com/rlshukhov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GenericHold\n\n![Go](https://github.com/rlshukhov/generichold/actions/workflows/go.yml/badge.svg)\n\nGenericHold is [BadgerHold](https://github.com/timshannon/badgerhold) extension provided simplest, generics-powered, type-safe API.\n\nGenericHold have rich tests coverage and pass all [BadgerHold](https://github.com/timshannon/badgerhold) unit tests.\n\n## Usage example\n\n```shell\ngo get github.com/rlshukhov/generichold\n```\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/rlshukhov/generichold\"\n\t\"github.com/timshannon/badgerhold/v4\"\n)\n\ntype Item struct {\n\tID       uint64 `badgerhold:\"key\"`\n\tCategory string `badgerholdIndex:\"Category\"`\n\tCreated  time.Time\n}\n\nfunc main() {\n\t// setup badger\n\toptions := badgerhold.DefaultOptions\n\toptions.InMemory = true\n\toptions.Logger = nil\n\n\t// setup badgerhold\n\tbh, err := badgerhold.Open(options)\n\tdefer bh.Close()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tstore := generichold.Open[Item](bh)\n\n\titems := getItems()\n\n\tvar ids []string\n\tfor _, item := range items {\n\t\terr := store.Insert(badgerhold.NextSequence(), \u0026item)\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\t// badgerhold.NextSequence() as key - will generate ID and set to original entity\n\t\tids = append(ids, strconv.FormatUint(item.ID, 10))\n\t}\n\tfmt.Println(strings.Join(ids, \",\"))\n\t// Output: 0,1,2,3\n\n\t// Find all items in the blue category that have been created in the past hour\n\tresult, err := store.Find(badgerhold.Where(\"Category\").Eq(\"blue\").And(\"Created\").Ge(time.Now().Add(-1 * time.Hour)))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Println(len(result))\n\t// Output: 1\n\n\tfmt.Println(result[0].ID)\n\t// Output: 3\n}\n\nfunc getItems() []Item {\n\treturn []Item{\n\t\t{\n\t\t\tCategory: \"blue\",\n\t\t\tCreated:  time.Now().Add(-4 * time.Hour),\n\t\t},\n\t\t{\n\t\t\tCategory: \"red\",\n\t\t\tCreated:  time.Now().Add(-3 * time.Hour),\n\t\t},\n\t\t{\n\t\t\tCategory: \"blue\",\n\t\t\tCreated:  time.Now().Add(-2 * time.Hour),\n\t\t},\n\t\t{\n\t\t\tCategory: \"blue\",\n\t\t\tCreated:  time.Now().Add(-20 * time.Minute),\n\t\t},\n\t}\n}\n```\n\n## TODO\n\n- Make `badgerhold.Criterion` generic version to avoid this limitation of BadgerHold:\n\u003e However if you have an existing slice of values to test against, you can't pass in that slice because it is not of type `[]interface{}`.\n\u003e ```go\n\u003e t := []string{\"1\", \"2\", \"3\", \"4\"}\n\u003e where := badgerhold.Where(\"Id\").In(t...) // compile error\n\u003e ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frlshukhov%2Fgenerichold","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frlshukhov%2Fgenerichold","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frlshukhov%2Fgenerichold/lists"}