session Transaction Execute sql wrapped in a transaction(abbr as tx), tx will automatic commit if no errors occurred
This commit is contained in:
parent
3b3f99f8a1
commit
cb7396945b
|
@ -4,6 +4,16 @@
|
|||
|
||||
package xorm
|
||||
|
||||
// Transaction Execute sql wrapped in a transaction(abbr as tx), tx will automatic commit if no errors occurred
|
||||
// Prevent the nested opening of multiple transactions by Engine().Transaction
|
||||
// Prevent the problem that "Begin Begin Commit Rollback" cannot be rolled back
|
||||
func (session *Session) Transaction(fn func(session *Session) (interface{}, error)) (interface{}, error) {
|
||||
if session.Tx() != nil {
|
||||
return fn(session)
|
||||
}
|
||||
return session.Engine().Transaction(fn)
|
||||
}
|
||||
|
||||
// Begin a transaction
|
||||
func (session *Session) Begin() error {
|
||||
if session.isAutoCommit {
|
||||
|
|
Loading…
Reference in New Issue