-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.go
65 lines (51 loc) · 1.5 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
package ceous
import (
"context"
"database/sql"
)
type (
TxProxy interface {
DBRunner
Commit() error
Rollback() error
}
BaseTxRunner struct {
tx *sql.Tx
}
)
// NewTx returns a new transaction abstraction.
func NewTx(tx *sql.Tx) *BaseTxRunner {
return &BaseTxRunner{
tx: tx,
}
}
func (tx *BaseTxRunner) Exec(query string, args ...interface{}) (sql.Result, error) {
return tx.tx.Exec(query, args...)
}
func (tx *BaseTxRunner) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
return tx.tx.ExecContext(ctx, query, args...)
}
func (tx *BaseTxRunner) Query(query string, args ...interface{}) (*sql.Rows, error) {
return tx.tx.Query(query, args...)
}
func (tx *BaseTxRunner) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
return tx.tx.QueryContext(ctx, query, args...)
}
func (tx *BaseTxRunner) QueryRow(query string, args ...interface{}) *sql.Row {
return tx.tx.QueryRow(query, args)
}
func (tx *BaseTxRunner) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
return tx.tx.QueryRowContext(ctx, query, args...)
}
func (tx *BaseTxRunner) Prepare(query string) (*sql.Stmt, error) {
return tx.tx.Prepare(query)
}
func (tx *BaseTxRunner) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) {
return tx.tx.PrepareContext(ctx, query)
}
func (tx *BaseTxRunner) Commit() error {
return tx.tx.Commit()
}
func (tx *BaseTxRunner) Rollback() error {
return tx.tx.Rollback()
}