{"id":15610402,"url":"https://github.com/awcodify/tx","last_synced_at":"2025-10-17T00:05:25.186Z","repository":{"id":125584439,"uuid":"271578729","full_name":"awcodify/tx","owner":"awcodify","description":"Simple example to database transaction with golang","archived":false,"fork":false,"pushed_at":"2020-06-23T09:54:44.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-04T15:47:59.683Z","etag":null,"topics":["commit","go","golang","rollback","sql","transaction"],"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/awcodify.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":"2020-06-11T15:15:22.000Z","updated_at":"2020-06-23T09:54:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"445b87ca-2089-4d14-9a07-944dccfbf3e4","html_url":"https://github.com/awcodify/tx","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"e2506d204f0ecaade33b11aa1825a55fce339e2a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awcodify%2Ftx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awcodify%2Ftx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awcodify%2Ftx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awcodify%2Ftx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awcodify","download_url":"https://codeload.github.com/awcodify/tx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246200296,"owners_count":20739563,"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":["commit","go","golang","rollback","sql","transaction"],"created_at":"2024-10-03T06:01:30.829Z","updated_at":"2025-10-17T00:05:20.148Z","avatar_url":"https://github.com/awcodify.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tx\nTransactions enforce the integrity of the database and guard the data against program errors or database break-downs [[=\u003e]](https://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html). \n\n## How to use\nWrap your transaction inside `Wrap` function. It determine between `Rollback()` and `Commit()` . See example below:\n```go\npackage main\n\nfunc main() {\n\t// ... some codes\n\ttx : tx.NewTx(db)\n\terr := tx.Wrap(createUserAndRole)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\t// ... some codes\n}\n\n// This our needs\nfunc createUserAndRole(t Transaction) (err error) {\n\tres, err := t.Exec(\"INSERT INTO users(name,email) VALUES(?,?)\", \"example\", \"example@email.com\")\n\tif err != nil {\n\t\treturn\n\t}\n\n\tuserId, err := res.LastInsertId()\n\tif err != nil {\n\t\treturn\n\t}\n\n\tres, err = t.Exec(\"INSERT INTO role(user_id,privileges) VALUES(?,?)\", userId, \"SELECT,INSERT\")\n\tif err != nil {\n\t\treturn\n\t}\n\n\treturn\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawcodify%2Ftx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawcodify%2Ftx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawcodify%2Ftx/lists"}