Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
module github.com/gobuffalo/nulls

go 1.16
go 1.25.0

require (
github.com/gofrs/uuid v4.3.0+incompatible
github.com/gofrs/uuid v4.4.0+incompatible
github.com/jmoiron/sqlx v1.3.5
github.com/mattn/go-sqlite3 v1.14.15
github.com/stretchr/testify v1.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/gofrs/uuid v4.3.0+incompatible h1:CaSVZxm5B+7o45rtab4jC2G37WGYX1zQfuU2i6DSvnc=
github.com/gofrs/uuid v4.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
Expand Down
1 change: 1 addition & 0 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (ns Time) MarshalJSON() ([]byte, error) {
// the propert representation of that value.
func (ns *Time) UnmarshalJSON(text []byte) error {
ns.Valid = false
ns.Time = time.Time{}
txt := string(text)
if txt == "null" || txt == "" {
return nil
Expand Down
31 changes: 31 additions & 0 deletions time_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package nulls_test

import (
"testing"
"time"

"github.com/gobuffalo/nulls"
"github.com/stretchr/testify/require"
)

func Test_TimeUnmarshalJSON(t *testing.T) {
r := require.New(t)

tn := time.Now()
tnStr := tn.Format(time.RFC3339)

ns := nulls.Time{}
r.NoError(ns.UnmarshalJSON([]byte("\"" + tnStr + "\"")))
r.True(ns.Valid)
r.Equal(tn.Format(time.RFC3339), ns.Time.Format(time.RFC3339))
}

func Test_TimeUnmarshalJSON_Overwrite(t *testing.T) {
r := require.New(t)

ns := nulls.NewTime(time.Now())

r.NoError(ns.UnmarshalJSON([]byte("null")))
r.False(ns.Valid)
r.True(ns.Time.IsZero())
}
Loading