-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransaction.go
72 lines (56 loc) · 1.92 KB
/
transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package mysqlx
import (
"database/sql"
"github.com/jmoiron/sqlx"
)
type tx struct {
sqlx *sqlx.Tx
db *xdb
}
// Begin create a transaction
func (db *xdb) Begin() (Tx, error) {
sqlxTx, err := db.Sqlx().Beginx()
if err != nil {
return nil, err
}
return &tx{
sqlx: sqlxTx,
db: db,
}, nil
}
func (tx *tx) Sqlx() *sqlx.Tx {
return tx.sqlx
}
func (tx *tx) Rollback() error {
return tx.sqlx.Rollback()
}
func (tx *tx) Commit() error {
return tx.sqlx.Commit()
}
func (tx *tx) Delete(prototype interface{}, args ...interface{}) (sql.Result, error) {
return tx.db.delete(tx.sqlx, prototype, args...)
}
func (tx *tx) Insert(v interface{}, opts ...Options) (sql.Result, error) {
return tx.db.insert(tx.sqlx, v, opts...)
}
func (tx *tx) InsertIfNotExists(insert interface{}, conds ...interface{}) (sql.Result, error) {
return tx.db.selectOrInsert(tx.sqlx, insert, nil, conds...)
}
func (tx *tx) InsertMany(records interface{}, opts ...Options) (result sql.Result, err error) {
return tx.db.insertMany(tx.sqlx, records, opts...)
}
func (tx *tx) InsertOnDuplicateKeyUpdate(v interface{}, updates map[string]interface{}, opts ...Options) (sql.Result, error) {
return tx.db.insertOnDuplicateKeyUpdate(tx.sqlx, v, updates, opts...)
}
func (tx *tx) InsertManyOnDuplicateKeyUpdate(records interface{}, updates map[string]interface{}, opts ...Options) (sql.Result, error) {
return tx.db.insertManyOnDuplicateKeyUpdate(tx.sqlx, records, updates, opts...)
}
func (tx *tx) Select(dst interface{}, args ...interface{}) error {
return tx.db.selectFunc(tx.sqlx, dst, args...)
}
func (tx *tx) SelectOrInsert(insert interface{}, selectResult interface{}, conds ...interface{}) (sql.Result, error) {
return tx.db.selectOrInsert(tx.sqlx, insert, selectResult, conds...)
}
func (tx *tx) Update(prototype interface{}, fields map[string]interface{}, args ...interface{}) (sql.Result, error) {
return tx.db.update(tx.sqlx, prototype, fields, args...)
}