-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx.go
45 lines (39 loc) · 1.58 KB
/
tx.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
package yesql
import (
"context"
"database/sql"
)
// Tx is an in-progress database transaction.
//
// A transaction must end with a call to Commit or Rollback.
//
// After a call to Commit or Rollback, all operations on the
// transaction fail with ErrTxDone.
//
// The statements prepared for a transaction by calling
// the transaction's Prepare or Stmt methods are closed
// by the call to Commit or Rollback.
type Tx struct {
*sql.Tx
cfg *Config
}
// ExecContext executes a query that doesn't return rows.
// The data object is a map/struct for any placeholder parameters in the query.
func (tx *Tx) ExecContext(ctx context.Context, query string, data interface{}) (sql.Result, error) {
return ExecContext(tx.Tx, ctx, query, data, tx.cfg)
}
// Exec executes a query without returning any rows.
// The data object is a map/struct for any placeholder parameters in the query.
func (tx *Tx) Exec(query string, data interface{}) (sql.Result, error) {
return tx.ExecContext(context.Background(), query, data)
}
// QueryContext executes a query that returns rows, typically a SELECT.
// The data object is a map/struct for any placeholder parameters in the query.
func (tx *Tx) QueryContext(ctx context.Context, query string, data interface{}) (*Rows, error) {
return QueryContext(tx.Tx, ctx, query, data, tx.cfg)
}
// Query executes a query that returns rows, typically a SELECT.
// The data object is a map/struct for any placeholder parameters in the query.
func (tx *Tx) Query(ctx context.Context, query string, data interface{}) (*Rows, error) {
return tx.QueryContext(context.Background(), query, data)
}