Documentation ¶
Overview ¶
sqltocsv 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/joho/sqltocsv
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) FloatFormat string // Format string for any float64 and float32 values (default is %v) 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 New ¶
New will return a Converter which will write your CSV however you like but will allow you to set a bunch of non-default behaivour like overriding headers or injecting a pre-processing step into your conversion
func (*Converter) SetRowPreProcessor ¶
func (c *Converter) SetRowPreProcessor(processor CsvPreProcessorFunc)
SetRowPreProcessor lets you specify a CsvPreprocessorFunc for this conversion
type CsvPreProcessorFunc ¶
type CsvPreProcessorFunc func(row []string, columnNames []string) (outputRow bool, processedRow []string)
CsvPreprocessorFunc is a function type for preprocessing 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.