From a8664c5cdb625913fcb0b6c667ac89bc2cd41686 Mon Sep 17 00:00:00 2001 From: myuon Date: Fri, 15 Dec 2023 21:32:24 +0900 Subject: [PATCH] fix: returns nil if value is nil --- gallon/input_sql.go | 5 +++++ test/mysql/mysql_to_file_test.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/gallon/input_sql.go b/gallon/input_sql.go index 7eca34e..2cb4769 100644 --- a/gallon/input_sql.go +++ b/gallon/input_sql.go @@ -153,6 +153,11 @@ type InputPluginSqlConfigSchemaColumn struct { } func (c InputPluginSqlConfigSchemaColumn) getValue(value interface{}) (interface{}, error) { + // if value is nil, returns nil anyway + if value == nil { + return nil, nil + } + switch c.Type { case "string": v, ok := value.(string) diff --git a/test/mysql/mysql_to_file_test.go b/test/mysql/mysql_to_file_test.go index 7067971..8af5936 100644 --- a/test/mysql/mysql_to_file_test.go +++ b/test/mysql/mysql_to_file_test.go @@ -81,6 +81,12 @@ func Migrate(db *sql.DB) error { return err } + // 50% chance to have partner + // NOTE: gofakeit does not support nullable bool + if gofakeit.Bool() { + v.HasPartner = nil + } + if _, err := query.Exec(v.ID, v.Name, v.Age, v.CreatedAt, v.Birthday, v.HasPartner); err != nil { return err }