Skip to content

Latest commit

 

History

History
37 lines (32 loc) · 986 Bytes

README.md

File metadata and controls

37 lines (32 loc) · 986 Bytes

XormPlus-TransactionManager

xormplus transaction-manager is the xorm plus automatic transaction manager. With this library, you don’t need to worry about global transaction.

Installation

go get github.com/RuiFG/xormpuls-transactionmanager 

Simple Example

package main

import (
	"github.com/RuiFG/xormpuls-transactionmanager"
    _ "github.com/go-sql-driver/mysql"
	"github.com/xormplus/xorm"
)

type Test struct {
	id          int
	description string
}

func main() {
	db, _ := xorm.NewEngine("mysql", "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=True&loc=Asia%2FShanghai")
	manager := transaction_manager.New(db)
	DynamicSession := manager.SessionFunc()
	test := Test{}
	_ = manager.Do(func(transaction *xorm.Transaction) error {
		return DynamicSession().Where("id = ?", 1).Find(&test)
	}, xorm.PROPAGATION_NEVER)
}

License

This project is under MIT License. See the LICENSE file for the full license text.