Passed
Push — main ( 25bc96...3a375b )
by Adriano
02:00
created

exportdata.NewExport   A

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nop 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
package exportdata
2
3
import (
4
	"adrianolaselva.github.io/csvql/pkg/exportdata"
5
	"adrianolaselva.github.io/csvql/pkg/exportdata/csv"
6
	"adrianolaselva.github.io/csvql/pkg/exportdata/jsonl"
7
	"database/sql"
8
	"fmt"
9
	"github.com/schollz/progressbar/v3"
10
)
11
12
const (
13
	CsvLineExportType  = "csv"
14
	JsonLineExportType = "jsonl"
15
)
16
17
func NewExport(exportType string, rows *sql.Rows, exportPath string, bar *progressbar.ProgressBar) (exportdata.Export, error) {
18
	switch exportType {
19
	case CsvLineExportType:
20
		return csv.NewCsvExport(rows, exportPath, bar), nil
21
	case JsonLineExportType:
22
		return jsonl.NewJsonlExport(rows, exportPath, bar), nil
23
	}
24
25
	return nil, fmt.Errorf("export type %s not defined", exportType)
26
}
27