-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathstmtx.go
61 lines (52 loc) · 2 KB
/
stmtx.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
package mssqlx
import (
"context"
"database/sql"
"github.com/jmoiron/sqlx"
)
// Stmtx wraps over sqlx.Stmt
type Stmtx struct {
*sqlx.Stmt
}
// Exec executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (s *Stmtx) Exec(args ...interface{}) (sql.Result, error) {
return s.ExecContext(context.Background(), args...)
}
// ExecContext executes a prepared statement with the given arguments and returns a Result summarizing the effect of the statement.
func (s *Stmtx) ExecContext(ctx context.Context, args ...interface{}) (result sql.Result, err error) {
r, err := retryFunc("stmt_exec", func() (interface{}, error) {
return s.Stmt.ExecContext(ctx, args...)
})
if err == nil {
result = r.(sql.Result)
}
return
}
// Query executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (s *Stmtx) Query(args ...interface{}) (*sql.Rows, error) {
return s.QueryContext(context.Background(), args...)
}
// QueryContext executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (s *Stmtx) QueryContext(ctx context.Context, args ...interface{}) (result *sql.Rows, err error) {
r, err := retryFunc("stmt_query", func() (interface{}, error) {
return s.Stmt.QueryContext(ctx, args...)
})
if err == nil {
result = r.(*sql.Rows)
}
return
}
// Queryx executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (s *Stmtx) Queryx(args ...interface{}) (*sqlx.Rows, error) {
return s.QueryxContext(context.Background(), args...)
}
// QueryxContext executes a prepared query statement with the given arguments and returns the query results as a *Rows.
func (s *Stmtx) QueryxContext(ctx context.Context, args ...interface{}) (result *sqlx.Rows, err error) {
r, err := retryFunc("stmt_query", func() (interface{}, error) {
return s.Stmt.QueryxContext(ctx, args...)
})
if err == nil {
result = r.(*sqlx.Rows)
}
return
}