Skip to content

Commit

Permalink
allow nil values for properties
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Sep 7, 2018
1 parent 3bc0ef1 commit f259acf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
12 changes: 8 additions & 4 deletions internal/inserter/eventinserter/eventinserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ func (i EventInserter) InsertSQL(def property.Types, t time.Time) (string, []int
}
sb.WriteRune(',')
sb.WriteString(string(pname))
val, err := ptype.ConvertValue(pval)
if err != nil {
return "", nil, errors.New("cannot read property (" + string(pname) + "): " + err.Error())
if pval != nil {
val, err := ptype.ConvertValue(pval)
if err != nil {
return "", nil, errors.New("cannot read property (" + string(pname) + "): " + err.Error())
}
values = append(values, val)
} else {
values = append(values, nil)
}
values = append(values, val)
}
sb.WriteString(") values (?, ?, ?")
for range e.Properties {
Expand Down
24 changes: 16 additions & 8 deletions internal/inserter/userinserter/userinserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ func (i UserInserter) InsertSQL(def property.Types, t time.Time) (string, []inte
}
sb.WriteRune(',')
sb.WriteString(string(pname))
val, err := ptype.ConvertValue(pval)
if err != nil {
return "", nil, errors.New("cannot read property (" + string(pname) + "): " + err.Error())
if pval != nil {
val, err := ptype.ConvertValue(pval)
if err != nil {
return "", nil, errors.New("cannot read property (" + string(pname) + "): " + err.Error())
}
values = append(values, val)
} else {
values = append(values, nil)
}
values = append(values, val)
}
sb.WriteString(") values (?, ?")
for range u.Properties {
Expand All @@ -48,11 +52,15 @@ func (i UserInserter) InsertSQL(def property.Types, t time.Time) (string, []inte
sb.WriteRune(',')
sb.WriteString(string(pname))
sb.WriteString("=?")
val, err := def[pname].ConvertValue(pval)
if err != nil {
return "", nil, err
if pval != nil {
val, err := def[pname].ConvertValue(pval)
if err != nil {
return "", nil, err
}
values = append(values, val)
} else {
values = append(values, nil)
}
values = append(values, val)
}
return sb.String(), values, nil
}
Expand Down

0 comments on commit f259acf

Please sign in to comment.