Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.
/ txn Public archive

An interface that aims to provide data consistency in modern architectures without reducing business logic to repositories.

License

Notifications You must be signed in to change notification settings

salihguru/txn

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

txn: Generic Distributed Transaction Management for Go

License

The 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.

Before of all, Check the Real World Example

Key Features

  • Distributed Transactions: Coordinate transactions across multiple data sources seamlessly.
  • Database Independence: Work with various databases (PostgreSQL, MongoDB etc.) using specialized adapters.
  • Clean Architecture: Maintain a clear separation of concerns, keeping your business logic decoupled from data access details.
  • Atomicity: Ensure that all operations within a transaction either succeed or fail together, maintaining data integrity.
  • Flexibility: Easily extend the framework by creating custom adapters for your specific data sources.

Installation

go get github.com/9ssi7/txn

go get github.com/9ssi7/txn/txngorm // For GORM Adapter
go get github.com/9ssi7/txn/txnmongo // For MongoDB Adapter
go get github.com/9ssi7/txn/txnsql // For Native SQL Adapter

Usage

  1. Create a Tx Instance:
tx := txn.New()
  1. Register Adapters:
gormAdapter := txngorm.New(gormDB)
tx.Register(gormAdapter)

mongoAdapter := txnmongo.New(mongoClient)
tx.Register(mongoAdapter)

sqlAdapter := txnsql.New(sqlDB)
tx.Register(sqlAdapter)

// Register more adapters as needed...
  1. Manage Transactions:
err := tx.Begin(context.Background())
if err != nil {
    // Handle error
}
defer tx.End(context.Background()) // Ensure resources are cleaned up

// Perform operations on each data source using their respective adapters
// ...

if err := tx.Commit(context.Background()); err != nil {
   tx.Rollback(context.Background())
    // Handle commit error
}

Adapters

The txn package supports multiple database adapters:

Contributing

Contributions are welcome! Please feel free to submit issues, bug reports, or pull requests.

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

About

An interface that aims to provide data consistency in modern architectures without reducing business logic to repositories.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published