Skip to content

Commit

Permalink
Merge pull request #825 from maniak89/null_int32
Browse files Browse the repository at this point in the history
Support sql.NullInt32 for write
  • Loading branch information
tealeg authored Nov 1, 2024
2 parents 7c33d07 + c8f4cd0 commit faa27f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions write.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func (r *Row) WriteSlice(e interface{}, cols int) int {
if cell.SetString(``); t.Valid {
cell.SetValue(t.Int64)
}
case sql.NullInt32:
cell := r.AddCell()
if cell.SetString(``); t.Valid {
cell.SetValue(t.Int32)
}
case sql.NullFloat64:
cell := r.AddCell()
if cell.SetString(``); t.Valid {
Expand Down Expand Up @@ -136,6 +141,11 @@ func (r *Row) WriteStruct(e interface{}, cols int) int {
if cell.SetString(``); t.Valid {
cell.SetValue(t.Int64)
}
case sql.NullInt32:
cell := r.AddCell()
if cell.SetString(``); t.Valid {
cell.SetValue(t.Int32)
}
case sql.NullFloat64:
cell := r.AddCell()
if cell.SetString(``); t.Valid {
Expand Down
4 changes: 2 additions & 2 deletions write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestWrite(t *testing.T) {
Raiting sql.NullFloat64
NullLastName sql.NullString
NullHasPhd sql.NullBool
NullGithubStars sql.NullInt64
NullGithubStars sql.NullInt32
NullRaiting sql.NullFloat64
}
testStruct := e{
Expand All @@ -59,7 +59,7 @@ func TestWrite(t *testing.T) {
sql.NullFloat64{Float64: 0.123, Valid: true},
sql.NullString{String: `What ever`, Valid: false},
sql.NullBool{Bool: true, Valid: false},
sql.NullInt64{Int64: 100, Valid: false},
sql.NullInt32{Int32: 100, Valid: false},
sql.NullFloat64{Float64: 0.123, Valid: false},
}
cnt := row.WriteStruct(&testStruct, -1)
Expand Down

0 comments on commit faa27f6

Please sign in to comment.