Skip to content

Commit

Permalink
implement Tx.GetContext and Tx.SelectContext
Browse files Browse the repository at this point in the history
Missing context dependent methods implementations added to Tx structure.

Fix jmoiron#286
  • Loading branch information
husio committed Feb 27, 2017
1 parent f407684 commit 1f451f3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions sqlx_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,36 @@ func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...interfa
return MustExecContext(ctx, tx, query, args...)
}

// QueryxContext within a transaction and context.
// Any placeholder parameters are replaced with supplied args.
func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
r, err := tx.Tx.QueryContext(ctx, query, args...)
if err != nil {
return nil, err
}
return &Rows{Rows: r, unsafe: tx.unsafe, Mapper: tx.Mapper}, err
}

// SelectContext within a transaction and context.
// Any placeholder parameters are replaced with supplied args.
func (tx *Tx) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return SelectContext(ctx, tx, dest, query, args...)
}

// GetContext within a transaction and context.
// Any placeholder parameters are replaced with supplied args.
// An error is returned if the result set is empty.
func (tx *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
return GetContext(ctx, tx, dest, query, args...)
}

// QueryRowxContext within a transaction and context.
// Any placeholder parameters are replaced with supplied args.
func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row {
rows, err := tx.Tx.QueryContext(ctx, query, args...)
return &Row{rows: rows, err: err, unsafe: tx.unsafe, Mapper: tx.Mapper}
}

// SelectContext using the prepared statement.
// Any placeholder parameters are replaced with supplied args.
func (s *Stmt) SelectContext(ctx context.Context, dest interface{}, args ...interface{}) error {
Expand Down

0 comments on commit 1f451f3

Please sign in to comment.