From 33b5b6ff660b77238a737a543ca12675c7f0c284 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 2 Mar 2022 10:03:44 +0200 Subject: [PATCH] fix: accept dest in select queries --- query_select.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/query_select.go b/query_select.go index bc52d0253..7a4a72418 100644 --- a/query_select.go +++ b/query_select.go @@ -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 } @@ -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