{"id":18655514,"url":"https://github.com/go-rel/changeset","last_synced_at":"2025-04-11T17:31:57.478Z","repository":{"id":37527694,"uuid":"271862288","full_name":"go-rel/changeset","owner":"go-rel","description":"Changeset for Golang","archived":false,"fork":false,"pushed_at":"2025-03-13T00:26:41.000Z","size":125,"stargazers_count":11,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T08:20:44.470Z","etag":null,"topics":["database","go","golang","hacktoberfest","orm"],"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/go-rel.png","metadata":{"files":{"readme":"README.md","changelog":"change.go","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"Fs02"}},"created_at":"2020-06-12T18:12:03.000Z","updated_at":"2024-11-27T00:26:11.000Z","dependencies_parsed_at":"2023-12-24T16:02:08.264Z","dependency_job_id":"f8fc2473-094c-4303-a5d0-6cfd429b0968","html_url":"https://github.com/go-rel/changeset","commit_stats":{"total_commits":85,"total_committers":5,"mean_commits":17.0,"dds":0.3058823529411765,"last_synced_commit":"3a1da8fc94f467224d9ec8a517a7f1cc77f6411a"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rel%2Fchangeset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rel%2Fchangeset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rel%2Fchangeset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-rel%2Fchangeset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-rel","download_url":"https://codeload.github.com/go-rel/changeset/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248449855,"owners_count":21105577,"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":["database","go","golang","hacktoberfest","orm"],"created_at":"2024-11-07T07:19:11.710Z","updated_at":"2025-04-11T17:31:57.448Z","avatar_url":"https://github.com/go-rel.png","language":"Go","funding_links":["https://github.com/sponsors/Fs02"],"categories":[],"sub_categories":[],"readme":"# changeset\n\n[![GoDoc](https://godoc.org/github.com/go-rel/changeset?status.svg)](https://godoc.org/github.com/go-rel/changeset) \n[![Build Status](https://travis-ci.org/go-rel/changeset.svg?branch=master)](https://travis-ci.org/go-rel/changeset) \n[![Go Report Card](https://goreportcard.com/badge/github.com/go-rel/changeset)](https://goreportcard.com/report/github.com/go-rel/changeset)\n[![codecov](https://codecov.io/gh/go-rel/changeset/branch/master/graph/badge.svg?token=LCJN4KR9N8)](https://codecov.io/gh/go-rel/changeset)\n[![Gitter chat](https://badges.gitter.im/go-rel/rel.png)](https://gitter.im/go-rel/rel)\n\nChangeset mutator for [REL](https://github.com/go-rel/rel). Changesets allow filtering, casting, validation and definition of constraints when manipulating structs.\n\n## Install\n\n```bash\ngo get github.com/go-rel/changeset\n```\n\n## Example\n\n```golang\npackage main\n\nimport (\n\t\"time\"\n\n\t\"github.com/go-rel/rel\"\n\t\"github.com/go-rel/rel/adapter/mysql\"\n\t\"github.com/go-rel/changeset\"\n\t\"github.com/go-rel/changeset/params\"\n)\n\ntype Product struct {\n\tID        int\n\tName      string\n\tPrice     int\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n}\n\n// ChangeProduct prepares data before database operation.\n// Such as casting value to appropriate types and perform validations.\nfunc ChangeProduct(product interface{}, params params.Params) *changeset.Changeset {\n\tch := changeset.Cast(product, params, []string{\"name\", \"price\"})\n\tchangeset.ValidateRequired(ch, []string{\"name\", \"price\"})\n\tchangeset.ValidateMin(ch, \"price\", 100)\n\treturn ch\n}\n\nfunc main() {\n    // initialize mysql adapter.\n    adapter, _ := mysql.Open(dsn)\n    defer adapter.Close()\n\n    // initialize rel's repo.\n    repo := rel.New(adapter)\n\n\tvar product Product\n\n\t// Inserting Products.\n\t// Changeset is used when creating or updating your data.\n\tch := ChangeProduct(product, params.Map{\n\t\t\"name\":  \"shampoo\",\n\t\t\"price\": 1000,\n\t})\n\n\tif ch.Error() != nil {\n\t\t// handle error\n\t}\n\n\t// Changeset can also be created directly from json string.\n\tjsonch := ChangeProduct(product, params.ParseJSON(`{\n\t\t\"name\":  \"soap\",\n\t\t\"price\": 2000,\n\t}`))\n\n\t// Create products with changeset and return the result to \u0026product,\n\tif err := repo.Insert(context.TODO(), \u0026product, ch); err != nil {\n\t\t// handle error\n\t}\n}\n```\n\n## License\n\nReleased under the [MIT License](https://github.com/go-rel/changeset/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-rel%2Fchangeset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-rel%2Fchangeset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-rel%2Fchangeset/lists"}