Documentation ¶
Overview ¶
sql2csv is a package to make it dead easy to turn arbitrary database query results (in the form of database/sql Rows) into CSV output.
Source and README at https://github.com/datatug/sql2csv
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Write ¶
Write will write a CSV file to the writer passed in (with headers) based on whatever is in the sql.Rows you pass in.
Types ¶
type Converter ¶
type Converter struct { Headers []string // Column headers to use (default is rows.Columns()) WriteHeaders bool // Flag to output headers in your CSV (default is true) TimeFormat string // Format string for any time.Time values (default is time's default) Delimiter rune // Delimiter to use in your CSV (default is comma) // contains filtered or unexported fields }
Converter does the actual work of converting the rows to CSV. There are a few settings you can override if you want to do some fancy stuff to your CSV.
func NewConverter ¶
NewConverter will return a Converter which will write your CSV however you like but will allow you to set a bunch of non-default behaviour like overriding headers or injecting a pre-processing step into your conversion
func (*Converter) SetRowPostProcessor ¶
func (c *Converter) SetRowPostProcessor(processor CsvRowPostProcessorFunc)
SetRowPostProcessor lets you specify a CsvRowPostProcessorFunc for this conversion
func (Converter) WriteFile ¶
WriteFile writes the CSV to the filename specified, return an error if problem
func (Converter) WriteString ¶
WriteString returns the CSV as a string and an error if something goes wrong
type CsvRowPostProcessorFunc ¶
type CsvRowPostProcessorFunc func(row []string, columnTypes []*sql.ColumnType) (outputRow bool, processedRow []string)
CsvRowPostProcessorFunc is a function type for postprocessing your CSV. It takes the columns after they've been munged into strings but before they've been passed into the CSV writer.
Return an outputRow of false if you want the row skipped otherwise return the processed Row slice as you want it written to the CSV.