georgysavva / scany

Library for scanning data from a database into Go structs and more
MIT License
1.31k stars 68 forks source link

pgxscanny.Get and rows.Close() #110

Closed sergey-tb closed 1 year ago

sergey-tb commented 1 year ago

Isn't calling of rows.Close() method missed in pgxscan.Get() implementation? Can't find it in sources.

err := pgxscan.Get(ctx, db, &user, findUserById, id)
func (api *API) Get(ctx context.Context, db Querier, dst interface{}, query string, args ...interface{}) error {
    rows, err := db.Query(ctx, query, args...)
        // shouldn't we defer here?
    if err != nil {
                 // exits without rows.Close()
        return fmt.Errorf("scany: query one result row: %w", err)
    }
    if err := api.ScanOne(dst, rows); err != nil {
        return fmt.Errorf("scanning one: %w", err)
    }
    return nil
}

Thanks

sergey-tb commented 1 year ago

I found out pgx connection.Query() will close rows in case of error. Issue could be closed, thanks.