Skip to content

Commit

Permalink
Merge pull request #470 from uptrace/fix/accept-dest-in-select
Browse files Browse the repository at this point in the history
fix: accept dest in select queries
  • Loading branch information
vmihailenco authored Mar 2, 2022
2 parents b393db0 + 33b5b6f commit 73bb41b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ func (q *SelectQuery) Rows(ctx context.Context) (*sql.Rows, error) {
return q.conn.QueryContext(ctx, query)
}

func (q *SelectQuery) Exec(ctx context.Context) (res sql.Result, err error) {
func (q *SelectQuery) Exec(ctx context.Context, dest ...interface{}) (res sql.Result, err error) {
if q.err != nil {
return nil, q.err
}
Expand All @@ -691,9 +691,21 @@ func (q *SelectQuery) Exec(ctx context.Context) (res sql.Result, err error) {

query := internal.String(queryBytes)

res, err = q.exec(ctx, q, query)
if err != nil {
return nil, err
if len(dest) > 0 {
model, err := q.getModel(dest)
if err != nil {
return nil, err
}

res, err = q.scan(ctx, q, query, model, true)
if err != nil {
return nil, err
}
} else {
res, err = q.exec(ctx, q, query)
if err != nil {
return nil, err
}
}

return res, nil
Expand Down

0 comments on commit 73bb41b

Please sign in to comment.