Skip to content

Commit

Permalink
fix: accept dest in select queries
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 2, 2022
1 parent cba24c1 commit 33b5b6f
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 33b5b6f

Please sign in to comment.