summaryrefslogtreecommitdiffstats
path: root/vendor/xorm.io/xorm/transaction.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/xorm.io/xorm/transaction.go')
-rw-r--r--vendor/xorm.io/xorm/transaction.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/vendor/xorm.io/xorm/transaction.go b/vendor/xorm.io/xorm/transaction.go
new file mode 100644
index 0000000000..4104103fd5
--- /dev/null
+++ b/vendor/xorm.io/xorm/transaction.go
@@ -0,0 +1,26 @@
+// Copyright 2018 The Xorm Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package xorm
+
+// Transaction Execute sql wrapped in a transaction(abbr as tx), tx will automatic commit if no errors occurred
+func (engine *Engine) Transaction(f func(*Session) (interface{}, error)) (interface{}, error) {
+ session := engine.NewSession()
+ defer session.Close()
+
+ if err := session.Begin(); err != nil {
+ return nil, err
+ }
+
+ result, err := f(session)
+ if err != nil {
+ return nil, err
+ }
+
+ if err := session.Commit(); err != nil {
+ return nil, err
+ }
+
+ return result, nil
+}