1
0
mirror of https://github.com/zhashkevych/go-sqlxmock.git synced 2025-11-29 21:57:41 +02:00

allow null values from csv string to be converted to nil

This commit is contained in:
gedi
2015-08-05 11:50:16 +03:00
parent dc0efdab8f
commit acfbd5d998
2 changed files with 42 additions and 1 deletions

12
rows.go
View File

@@ -7,6 +7,16 @@ import (
"strings"
)
// CSVColumnParser is a function which converts trimmed csv
// column string to a []byte representation.
var CSVColumnParser = func(s string) []byte {
switch {
case strings.ToLower(s) == "null":
return nil
}
return []byte(s)
}
// Rows interface allows to construct rows
// which also satisfies database/sql/driver.Rows interface
type Rows interface {
@@ -113,7 +123,7 @@ func (r *rows) FromCSVString(s string) Rows {
row := make([]driver.Value, len(r.cols))
for i, v := range res {
row[i] = []byte(strings.TrimSpace(v))
row[i] = CSVColumnParser(strings.TrimSpace(v))
}
r.rows = append(r.rows, row)
}