diff --git a/json_array.go b/json_array.go index 41a649a..6abb337 100644 --- a/json_array.go +++ b/json_array.go @@ -36,9 +36,9 @@ func (f JSONArray[T]) String() string { func (f *JSONArray[T]) SetValue(value any) error { switch vl := value.(type) { case []T: - *f = vl + *f = append(*f, vl...) case *[]T: - *f = *vl + *f = append(*f, *vl...) case nil: return ErrNullValueNotAllowed default: @@ -101,7 +101,7 @@ func (f *JSONArray[T]) UnmarshalJSON(b []byte) error { if err := json.Unmarshal(b, &res); err != nil { return err } - *f = (*f)[:0] + *f = append((*f)[:0], res...) return nil } diff --git a/nullable_json_arrray.go b/nullable_json_arrray.go index 8db8d60..115c2ce 100644 --- a/nullable_json_arrray.go +++ b/nullable_json_arrray.go @@ -1,6 +1,8 @@ package gosql -import "database/sql/driver" +import ( + "database/sql/driver" +) // NullableJSONArray object type NullableJSONArray[T any] JSONArray[T] @@ -43,7 +45,7 @@ func (f NullableJSONArray[T]) Value() (driver.Value, error) { } // Scan value from database -func (f *NullableJSONArray[T]) Scan(value interface{}) error { +func (f *NullableJSONArray[T]) Scan(value any) error { if value == nil { *f = nil return nil diff --git a/nullable_json_arrray_test.go b/nullable_json_arrray_test.go index e799fb8..7f2284e 100644 --- a/nullable_json_arrray_test.go +++ b/nullable_json_arrray_test.go @@ -56,4 +56,11 @@ func TestNullableJSONArray(t *testing.T) { v, _ := js.Value() assert.Nil(t, v) }) + + t.Run("scan", func(t *testing.T) { + var js NullableJSONArray[int] + if assert.NoError(t, js.Scan([]byte("[1,2,3]"))) { + assert.ElementsMatch(t, []int{1, 2, 3}, js) + } + }) }