We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent acacba5 commit eb8041eCopy full SHA for eb8041e
sqlrunner.go
@@ -122,7 +122,7 @@ func (this *Session) SetParserFactory(fac ParserFactory) {
122
//开启事务执行语句
123
//返回nil则提交,返回error回滚
124
//抛出异常错误触发回滚
125
-func (this *Session) Tx(txFunc func(session *Session) error) {
+func (this *Session) Tx(txFunc func(session *Session) error) error {
126
this.session.Begin()
127
defer func() {
128
if r := recover(); r != nil {
@@ -131,10 +131,12 @@ func (this *Session) Tx(txFunc func(session *Session) error) {
131
}
132
}()
133
134
- if txFunc(this) != nil {
+ if err := txFunc(this); err != nil {
135
this.session.Rollback()
136
+ return err
137
} else {
138
this.session.Commit()
139
+ return nil
140
141
142
0 commit comments