Skip to content

Commit

Permalink
Merge pull request #6 from myuon/issue-5
Browse files Browse the repository at this point in the history
fix: returns nil if value is nil
  • Loading branch information
myuon committed Dec 15, 2023
2 parents 64a5418 + a8664c5 commit 9955c96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gallon/input_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/mysql/mysql_to_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9955c96

Please sign in to comment.