From c8f4cd0132b8eb83bd9d24b9c76a554b3a7c7ef9 Mon Sep 17 00:00:00 2001 From: Ilya Ageev Date: Tue, 22 Oct 2024 12:08:17 +0400 Subject: [PATCH] Support sql.NullInt32 for write --- write.go | 10 ++++++++++ write_test.go | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/write.go b/write.go index 47cbed2c..5daaf1e4 100644 --- a/write.go +++ b/write.go @@ -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 { @@ -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 { diff --git a/write_test.go b/write_test.go index 2fd06363..0eb7d204 100644 --- a/write_test.go +++ b/write_test.go @@ -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{ @@ -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)