Skip to content

Commit

Permalink
If writeHeaders set to false, dont write to csv buffer.
Browse files Browse the repository at this point in the history
Signed-off-by: thatInfrastructureGuy <[email protected]>
  • Loading branch information
thatInfrastructureGuy committed Feb 1, 2021
1 parent 8fbbac9 commit ad1b725
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A library designed to convert sql.Rows result from a query into a **CSV.GZIP** f

### Installation
```go
go get github.com/thatInfrastructureGuy/sqltocsvgzip@v0.0.10
go get github.com/thatInfrastructureGuy/sqltocsvgzip@v0.0.13
```

_Note: Please do not use master branch. Master branch may contain breaking changes. Use tags instead._
Expand Down
24 changes: 12 additions & 12 deletions csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ func (c *Converter) setCSVHeaders(csvWriter *csv.Writer) ([]string, int, error)
return nil, 0, err
}

if c.WriteHeaders {
// use Headers if set, otherwise default to
// query Columns
if len(c.Headers) > 0 {
headers = c.Headers
} else {
headers = columnNames
}
// Use Headers if set, otherwise default to
// query Columns
if len(c.Headers) > 0 {
headers = c.Headers
} else {
headers = columnNames
}

// Write to CSV Buffer
err = csvWriter.Write(headers)
if err != nil {
return nil, 0, err
if c.WriteHeaders {
err = csvWriter.Write(headers)
if err != nil {
return nil, 0, err
}
csvWriter.Flush()
}
csvWriter.Flush()

return headers, len(headers), nil
}
Expand Down

0 comments on commit ad1b725

Please sign in to comment.