Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add missing methods #941

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sqlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type ColScanner interface {
type Queryer interface {
Query(query string, args ...interface{}) (*sql.Rows, error)
Queryx(query string, args ...interface{}) (*Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Adding a missing method to this interface.

We have Query/Queryx, and QueryRowx, but this method was missing.

QueryRowx(query string, args ...interface{}) *Row
}

Expand Down Expand Up @@ -563,6 +564,10 @@ func (q *qStmt) Queryx(query string, args ...interface{}) (*Rows, error) {
return &Rows{Rows: r, unsafe: q.Stmt.unsafe, Mapper: q.Stmt.Mapper}, err
}

func (q *qStmt) QueryRow(query string, args ...interface{}) *sql.Row {
return q.Stmt.QueryRow(args...)
}

func (q *qStmt) QueryRowx(query string, args ...interface{}) *Row {
rows, err := q.Stmt.Query(args...)
return &Row{rows: rows, err: err, unsafe: q.Stmt.unsafe, Mapper: q.Stmt.Mapper}
Expand Down
11 changes: 11 additions & 0 deletions sqlx_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func ConnectContext(ctx context.Context, driverName, dataSourceName string) (*DB
type QueryerContext interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Adding a missing method to this interface.

We have QueryContext/QueryxContext, and QueryRowxContext, but this method was missing.

QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row
}

Expand Down Expand Up @@ -353,6 +354,12 @@ func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...interf
return &Row{rows: rows, err: err, unsafe: tx.unsafe, Mapper: tx.Mapper}
}

// NamedQueryContext using this DB.
// Any named placeholder parameters are replaced with fields from arg.
func (tx *Tx) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*Rows, error) {
return NamedQueryContext(ctx, tx, query, arg)
}
Comment on lines +359 to +361
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

This method exists on DB, but was missing from Tx.

This is the only query-related method I found that is needed to allow these two types to be used interchangeably.


// NamedExecContext using this Tx.
// Any named placeholder parameters are replaced with fields from arg.
func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
Expand Down Expand Up @@ -405,6 +412,10 @@ func (q *qStmt) QueryxContext(ctx context.Context, query string, args ...interfa
return &Rows{Rows: r, unsafe: q.Stmt.unsafe, Mapper: q.Stmt.Mapper}, err
}

func (q *Stmt) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
return q.Stmt.QueryRowContext(ctx, args...)
}

func (q *qStmt) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row {
rows, err := q.Stmt.QueryContext(ctx, args...)
return &Row{rows: rows, err: err, unsafe: q.Stmt.unsafe, Mapper: q.Stmt.Mapper}
Expand Down