{"id":19273592,"url":"https://github.com/zikwall/nullable","last_synced_at":"2026-06-18T13:31:08.223Z","repository":{"id":260159140,"uuid":"880487184","full_name":"zikwall/nullable","owner":"zikwall","description":"A generic utility for representing optional (nullable) values in Go, with full JSON serialization support.","archived":false,"fork":false,"pushed_at":"2025-11-12T13:52:17.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-12T15:20:21.246Z","etag":null,"topics":["go","golang","nullable"],"latest_commit_sha":null,"homepage":"","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/zikwall.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":"2024-10-29T20:14:47.000Z","updated_at":"2025-11-12T13:50:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0f687cb-06c4-4b6f-a8f4-81442a8cd820","html_url":"https://github.com/zikwall/nullable","commit_stats":null,"previous_names":["zikwall/nullable"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zikwall/nullable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zikwall%2Fnullable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zikwall%2Fnullable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zikwall%2Fnullable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zikwall%2Fnullable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zikwall","download_url":"https://codeload.github.com/zikwall/nullable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zikwall%2Fnullable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34493355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","golang","nullable"],"created_at":"2024-11-09T20:43:33.614Z","updated_at":"2026-06-18T13:31:08.215Z","avatar_url":"https://github.com/zikwall.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![build](https://github.com/zikwall/nullable/workflows/golangci_lint/badge.svg)](https://github.com/zikwall/nullable/actions)\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eNullable\u003c/h1\u003e\n\u003c/div\u003e\n\nnullable provides a *type-safe and JSON-friendly way* to represent optional (nullable) values in Go.\nIt eliminates unsafe pointer juggling and keeps your models clean, especially when dealing with APIs or databases.\n\n## ✨ Features\n\n- ✅ Type-safe — no interface{} or reflection\n- 🧠 Generic — works with any type (int, string, uuid.UUID, structs…)\n- 🔄 JSON-aware — encodes and decodes null seamlessly\n- 💾 DB-friendly — ideal for Postgres jsonb or SQL NULL values\n- 🧰 Minimal API — New, Null, FromRef, Set, Unset, IsNull, Value, Ref\n\n## 📘 Comparison\n\n| Approach                          | Drawbacks                                  | nullable advantage                      |\n| --------------------------------- | ------------------------------------------ | --------------------------------------- |\n| `*T` pointers                     | risk of nil dereference, not JSON-friendly | safe, JSON `null` handled automatically |\n| `sql.NullString`, `sql.NullInt64` | separate type per kind                     | one generic type for all                |\n| `interface{}`                     | loses type safety                          | strongly typed generics                 |\n\n\n## Install\n\n- `$ go get -u github.com/zikwall/nullable`\n\n## 🚀 Usage\n\nWorking with optional values in Go often ends up with *T, sql.NullString, or awkward omitempty tricks.\nnullable fixes that — it gives you a clean, generic, and JSON-safe way to express “this field might be missing”.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/google/uuid\"\n\t\"yourmodule/nullable\"\n)\n\ntype DeviceInfo struct {\n\tDeviceID        nullable.Nullable[string]    `json:\"device_id\"`\n\tGUID            nullable.Nullable[uuid.UUID] `json:\"guid\"`\n\tDeviceType      nullable.Nullable[string]    `json:\"device_type\"`\n\tOSName          nullable.Nullable[string]    `json:\"os_name\"`\n\tUserID          nullable.Nullable[int64]     `json:\"user_id\"`\n\tLastSeenAt      nullable.Nullable[time.Time] `json:\"last_seen_at\"`\n}\n\nfunc main() {\n\tvar info DeviceInfo\n\n\t// Set some values\n\tinfo.GUID = nullable.New(uuid.New())\n\tinfo.DeviceType = nullable.New(\"mobile\")\n\n\tfmt.Println(info.GUID.NotNull()) // true\n\tfmt.Println(info.DeviceType.Value()) // \"mobile\"\n\n\t// Create from pointer reference\n\tval := int64(42)\n\tnum := nullable.FromRef(\u0026val)\n\tfmt.Println(num.Value()) // 42\n\n\t// Unset values explicitly\n\tnum.Unset()\n\tfmt.Println(num.IsNull()) // true\n\n\t// Convert to/from JSON safely\n\tdata, _ := json.Marshal(info)\n\tfmt.Println(string(data))\n}\n```\n\nOutput:\n\n```json\n{\n  \"device_id\": null,\n  \"guid\": \"c8f8ad4a-6e21-4e6b-a8b1-fb99d5ce1d7b\",\n  \"device_type\": \"mobile\",\n  \"os_name\": null,\n  \"user_id\": null,\n  \"last_seen_at\": null\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzikwall%2Fnullable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzikwall%2Fnullable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzikwall%2Fnullable/lists"}