{"id":17520789,"url":"https://github.com/9ssi7/txn","last_synced_at":"2025-04-23T16:10:13.141Z","repository":{"id":249368895,"uuid":"831314821","full_name":"9ssi7/txn","owner":"9ssi7","description":"An interface that aims to provide data consistency in modern architectures without reducing business logic to repositories.","archived":false,"fork":false,"pushed_at":"2025-04-10T21:09:33.000Z","size":85,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T16:09:53.488Z","etag":null,"topics":["data-consistency","transaction-processing"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/9ssi7/txn","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/9ssi7.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":["9ssi7"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"custom":null}},"created_at":"2024-07-20T07:41:09.000Z","updated_at":"2025-04-10T21:10:08.000Z","dependencies_parsed_at":"2024-08-13T01:46:15.228Z","dependency_job_id":null,"html_url":"https://github.com/9ssi7/txn","commit_stats":null,"previous_names":["9ssi7/txn"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9ssi7%2Ftxn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9ssi7%2Ftxn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9ssi7%2Ftxn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9ssi7%2Ftxn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/9ssi7","download_url":"https://codeload.github.com/9ssi7/txn/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250468270,"owners_count":21435452,"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":["data-consistency","transaction-processing"],"created_at":"2024-10-20T11:24:37.568Z","updated_at":"2025-04-23T16:10:13.135Z","avatar_url":"https://github.com/9ssi7.png","language":"Go","readme":"# txn: Generic Distributed Transaction Management for Go\n\n[![GoDoc](https://godoc.org/github.com/9ssi7/txn?status.svg)](https://pkg.go.dev/github.com/9ssi7/txn)\n![Project status](https://img.shields.io/badge/version-1.0.2-green.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/9ssi7/txn)](https://goreportcard.com/report/github.com/9ssi7/txn)\n\nThe `txn` package provides a robust and flexible framework for managing distributed transactions across multiple data sources in your Go applications. By harnessing the power of Go generics, `txn` enables a clean, database-agnostic approach to transaction handling, ensuring data consistency and atomicity even in complex, distributed environments.\n\n## Before of all, Check the [Real World Example](https://github.com/9ssi7/teknasyon.banking/blob/main/apps/banking/internal/app/commands/money_transfer.go#L41)\n\n## Key Features\n\n* **Distributed Transactions:** Coordinate transactions across multiple data sources seamlessly.\n* **Clean Architecture:** Maintain a clear separation of concerns, keeping your business logic decoupled from data access details.\n* **Atomicity:** Ensure that all operations within a transaction either succeed or fail together, maintaining data integrity.\n* **Flexibility:** Easily extend the framework by creating custom adapters for your specific data sources.\n\nNote:\nDatabase independency not possible with this package. You need to use the same database for all adapters. For example, if you are using GORM, you need to use GORM for all adapters. If you are using MongoDB, you need to use MongoDB for all adapters. If GORM throws an error but MongoDB doesn't, you need to handle it yourself. This package doesn't handle that. It only provides a way to manage transactions across multiple data sources.\n\n## Installation\n\n```bash\ngo get github.com/9ssi7/txn\n\ngo get github.com/9ssi7/txn/txngorm // For GORM Adapter\ngo get github.com/9ssi7/txn/txnmongo // For MongoDB Adapter\ngo get github.com/9ssi7/txn/txnsql // For Native SQL Adapter\n```\n\n## Usage\n\n1. **Create a Tx Instance:**\n\n```go\ntx := txn.New()\n```\n\n2. **Register Adapters:**\n\n```go\ntx.Register(txngorm.New(gormDB), txnmongo.New(mongoClient), txnsql.New(sqlDB))\n\n// Register more adapters as needed...\n```\n\n3. **Manage Transactions:**\n\n```go\nfunc transaction() (err error) {\n    defer func() {\n        if err != nil {\n            tx.Rollback(context.Background())\n        }\n    }()\n    if err := tx.Begin(context.Background()); err != nil {\n        return err\n    }\n    // Perform operations on each data source using their respective adapters\n    // ...\n\n    if err := tx.Commit(context.Background()); err != nil {\n    return err\n    }\n    return nil\n}\n\n\n```\n\n## Adapters\n\nThe `txn` package supports multiple database adapters:\n\n* **txngorm:** [GORM](./txngorm) \n* **txnmongo:** [MongoDB](./txnmongo)\n* **txnsql:** [Native SQL](./txnsql)\n\n## Contributing\n\nContributions are welcome! Please feel free to submit issues, bug reports, or pull requests.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","funding_links":["https://github.com/sponsors/9ssi7"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F9ssi7%2Ftxn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F9ssi7%2Ftxn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F9ssi7%2Ftxn/lists"}