Skip to content

Commit 0e95b1a

Browse files
committed
set=true in more places
1 parent 8173e16 commit 0e95b1a

20 files changed

+75
-17
lines changed

bool.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88

9-
"github.com/volatiletech/null/v8/convert"
9+
"github.com/razor-1/null/v9/convert"
1010
)
1111

1212
// Bool is a nullable bool.
@@ -62,6 +62,7 @@ func (b *Bool) UnmarshalJSON(data []byte) error {
6262

6363
// UnmarshalText implements encoding.TextUnmarshaler.
6464
func (b *Bool) UnmarshalText(text []byte) error {
65+
b.set = true
6566
if text == nil || len(text) == 0 {
6667
b.Valid = false
6768
return nil
@@ -107,6 +108,7 @@ func (b Bool) MarshalText() ([]byte, error) {
107108
func (b *Bool) SetValid(v bool) {
108109
b.Bool = v
109110
b.Valid = true
111+
b.set = true
110112
}
111113

112114
// Ptr returns a pointer to this Bool's value, or a nil pointer if this Bool is null.
@@ -124,6 +126,7 @@ func (b Bool) IsZero() bool {
124126

125127
// Scan implements the Scanner interface.
126128
func (b *Bool) Scan(value interface{}) error {
129+
b.set = true
127130
if value == nil {
128131
b.Bool, b.Valid = false, false
129132
return nil

byte.go

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (b *Byte) UnmarshalJSON(data []byte) error {
6666

6767
// UnmarshalText implements encoding.TextUnmarshaler.
6868
func (b *Byte) UnmarshalText(text []byte) error {
69+
b.set = true
6970
if text == nil || len(text) == 0 {
7071
b.Valid = false
7172
return nil
@@ -100,6 +101,7 @@ func (b Byte) MarshalText() ([]byte, error) {
100101
func (b *Byte) SetValid(n byte) {
101102
b.Byte = n
102103
b.Valid = true
104+
b.set = true
103105
}
104106

105107
// Ptr returns a pointer to this Byte's value, or a nil pointer if this Byte is null.
@@ -117,6 +119,7 @@ func (b Byte) IsZero() bool {
117119

118120
// Scan implements the Scanner interface.
119121
func (b *Byte) Scan(value interface{}) error {
122+
b.set = true
120123
if value == nil {
121124
b.Byte, b.Valid = 0, false
122125
return nil

bytes.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"database/sql/driver"
66
"encoding/json"
77

8-
"github.com/volatiletech/null/v8/convert"
8+
"github.com/razor-1/null/v9/convert"
99
)
1010

1111
// NullBytes is a global byte slice of JSON null
@@ -67,6 +67,7 @@ func (b *Bytes) UnmarshalJSON(data []byte) error {
6767

6868
// UnmarshalText implements encoding.TextUnmarshaler.
6969
func (b *Bytes) UnmarshalText(text []byte) error {
70+
b.set = true
7071
if len(text) == 0 {
7172
b.Bytes = nil
7273
b.Valid = false
@@ -98,6 +99,7 @@ func (b Bytes) MarshalText() ([]byte, error) {
9899
func (b *Bytes) SetValid(n []byte) {
99100
b.Bytes = n
100101
b.Valid = true
102+
b.set = true
101103
}
102104

103105
// Ptr returns a pointer to this Bytes's value, or a nil pointer if this Bytes is null.
@@ -115,6 +117,7 @@ func (b Bytes) IsZero() bool {
115117

116118
// Scan implements the Scanner interface.
117119
func (b *Bytes) Scan(value interface{}) error {
120+
b.set = true
118121
if value == nil {
119122
b.Bytes, b.Valid = []byte{}, false
120123
return nil

float32.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"strconv"
88

9-
"github.com/volatiletech/null/v8/convert"
9+
"github.com/razor-1/null/v9/convert"
1010
)
1111

1212
// Float32 is a nullable float32.
@@ -63,6 +63,7 @@ func (f *Float32) UnmarshalJSON(data []byte) error {
6363

6464
// UnmarshalText implements encoding.TextUnmarshaler.
6565
func (f *Float32) UnmarshalText(text []byte) error {
66+
f.set = true
6667
if text == nil || len(text) == 0 {
6768
f.Valid = false
6869
return nil
@@ -96,6 +97,7 @@ func (f Float32) MarshalText() ([]byte, error) {
9697
func (f *Float32) SetValid(n float32) {
9798
f.Float32 = n
9899
f.Valid = true
100+
f.set = true
99101
}
100102

101103
// Ptr returns a pointer to this Float32's value, or a nil pointer if this Float32 is null.
@@ -113,6 +115,7 @@ func (f Float32) IsZero() bool {
113115

114116
// Scan implements the Scanner interface.
115117
func (f *Float32) Scan(value interface{}) error {
118+
f.set = true
116119
if value == nil {
117120
f.Float32, f.Valid = 0, false
118121
return nil

float64.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"strconv"
88

9-
"github.com/volatiletech/null/v8/convert"
9+
"github.com/razor-1/null/v9/convert"
1010
)
1111

1212
// Float64 is a nullable float64.
@@ -61,6 +61,7 @@ func (f *Float64) UnmarshalJSON(data []byte) error {
6161

6262
// UnmarshalText implements encoding.TextUnmarshaler.
6363
func (f *Float64) UnmarshalText(text []byte) error {
64+
f.set = true
6465
if text == nil || len(text) == 0 {
6566
f.Valid = false
6667
return nil
@@ -91,6 +92,7 @@ func (f Float64) MarshalText() ([]byte, error) {
9192
func (f *Float64) SetValid(n float64) {
9293
f.Float64 = n
9394
f.Valid = true
95+
f.set = true
9496
}
9597

9698
// Ptr returns a pointer to this Float64's value, or a nil pointer if this Float64 is null.
@@ -108,6 +110,7 @@ func (f Float64) IsZero() bool {
108110

109111
// Scan implements the Scanner interface.
110112
func (f *Float64) Scan(value interface{}) error {
113+
f.set = true
111114
if value == nil {
112115
f.Float64, f.Valid = 0, false
113116
return nil

go.mod

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ module github.com/razor-1/null/v9
22

33
go 1.14
44

5-
require github.com/volatiletech/randomize v0.0.1
5+
require (
6+
github.com/volatiletech/randomize v0.0.1
7+
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4
44
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
55
github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU=
66
github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA=
7+
github.com/volatiletech/null/v8 v8.1.0 h1:eAO3I31A5R04usY5SKMMfDcOCnEGyT/T4wRI0JVGp4U=
8+
github.com/volatiletech/null/v8 v8.1.0/go.mod h1:98DbwNoKEpRrYtGjWFctievIfm4n4MxG0A6EBUcoS5g=
79
github.com/volatiletech/randomize v0.0.1 h1:eE5yajattWqTB2/eN8df4dw+8jwAzBtbdo5sbWC4nMk=
810
github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xuj2mXrXBjWaRTlY=
911
github.com/volatiletech/strmangle v0.0.1 h1:UKQoHmY6be/R3tSvD2nQYrH41k43OJkidwEiC74KIzk=

int.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"math"
88
"strconv"
99

10-
"github.com/volatiletech/null/v8/convert"
10+
"github.com/razor-1/null/v9/convert"
1111
)
1212

1313
// Int is an nullable int.
@@ -65,6 +65,7 @@ func (i *Int) UnmarshalJSON(data []byte) error {
6565

6666
// UnmarshalText implements encoding.TextUnmarshaler.
6767
func (i *Int) UnmarshalText(text []byte) error {
68+
i.set = true
6869
if text == nil || len(text) == 0 {
6970
i.Valid = false
7071
return nil
@@ -98,6 +99,7 @@ func (i Int) MarshalText() ([]byte, error) {
9899
func (i *Int) SetValid(n int) {
99100
i.Int = n
100101
i.Valid = true
102+
i.set = true
101103
}
102104

103105
// Ptr returns a pointer to this Int's value, or a nil pointer if this Int is null.
@@ -115,6 +117,7 @@ func (i Int) IsZero() bool {
115117

116118
// Scan implements the Scanner interface.
117119
func (i *Int) Scan(value interface{}) error {
120+
i.set = true
118121
if value == nil {
119122
i.Int, i.Valid = 0, false
120123
return nil

int16.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"math"
99
"strconv"
1010

11-
"github.com/volatiletech/null/v8/convert"
11+
"github.com/razor-1/null/v9/convert"
1212
)
1313

1414
// Int16 is an nullable int16.
@@ -69,6 +69,7 @@ func (i *Int16) UnmarshalJSON(data []byte) error {
6969

7070
// UnmarshalText implements encoding.TextUnmarshaler.
7171
func (i *Int16) UnmarshalText(text []byte) error {
72+
i.set = true
7273
if text == nil || len(text) == 0 {
7374
i.Valid = false
7475
return nil
@@ -102,6 +103,7 @@ func (i Int16) MarshalText() ([]byte, error) {
102103
func (i *Int16) SetValid(n int16) {
103104
i.Int16 = n
104105
i.Valid = true
106+
i.set = true
105107
}
106108

107109
// Ptr returns a pointer to this Int16's value, or a nil pointer if this Int16 is null.
@@ -119,6 +121,7 @@ func (i Int16) IsZero() bool {
119121

120122
// Scan implements the Scanner interface.
121123
func (i *Int16) Scan(value interface{}) error {
124+
i.set = true
122125
if value == nil {
123126
i.Int16, i.Valid = 0, false
124127
return nil

int32.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"math"
99
"strconv"
1010

11-
"github.com/volatiletech/null/v8/convert"
11+
"github.com/razor-1/null/v9/convert"
1212
"github.com/volatiletech/randomize"
1313
)
1414

@@ -70,6 +70,7 @@ func (i *Int32) UnmarshalJSON(data []byte) error {
7070

7171
// UnmarshalText implements encoding.TextUnmarshaler.
7272
func (i *Int32) UnmarshalText(text []byte) error {
73+
i.set = true
7374
if text == nil || len(text) == 0 {
7475
i.Valid = false
7576
return nil
@@ -103,6 +104,7 @@ func (i Int32) MarshalText() ([]byte, error) {
103104
func (i *Int32) SetValid(n int32) {
104105
i.Int32 = n
105106
i.Valid = true
107+
i.set = true
106108
}
107109

108110
// Ptr returns a pointer to this Int32's value, or a nil pointer if this Int32 is null.
@@ -120,6 +122,7 @@ func (i Int32) IsZero() bool {
120122

121123
// Scan implements the Scanner interface.
122124
func (i *Int32) Scan(value interface{}) error {
125+
i.set = true
123126
if value == nil {
124127
i.Int32, i.Valid = 0, false
125128
return nil

int64.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"strconv"
88

9-
"github.com/volatiletech/null/v8/convert"
9+
"github.com/razor-1/null/v9/convert"
1010
)
1111

1212
// Int64 is an nullable int64.
@@ -61,6 +61,7 @@ func (i *Int64) UnmarshalJSON(data []byte) error {
6161

6262
// UnmarshalText implements encoding.TextUnmarshaler.
6363
func (i *Int64) UnmarshalText(text []byte) error {
64+
i.set = true
6465
if text == nil || len(text) == 0 {
6566
i.Valid = false
6667
return nil
@@ -91,6 +92,7 @@ func (i Int64) MarshalText() ([]byte, error) {
9192
func (i *Int64) SetValid(n int64) {
9293
i.Int64 = n
9394
i.Valid = true
95+
i.set = true
9496
}
9597

9698
// Ptr returns a pointer to this Int64's value, or a nil pointer if this Int64 is null.
@@ -108,6 +110,7 @@ func (i Int64) IsZero() bool {
108110

109111
// Scan implements the Scanner interface.
110112
func (i *Int64) Scan(value interface{}) error {
113+
i.set = true
111114
if value == nil {
112115
i.Int64, i.Valid = 0, false
113116
return nil

int8.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"math"
99
"strconv"
1010

11-
"github.com/volatiletech/null/v8/convert"
11+
"github.com/razor-1/null/v9/convert"
1212
)
1313

1414
// Int8 is an nullable int8.
@@ -69,6 +69,7 @@ func (i *Int8) UnmarshalJSON(data []byte) error {
6969

7070
// UnmarshalText implements encoding.TextUnmarshaler.
7171
func (i *Int8) UnmarshalText(text []byte) error {
72+
i.set = true
7273
if text == nil || len(text) == 0 {
7374
i.Valid = false
7475
return nil
@@ -102,6 +103,7 @@ func (i Int8) MarshalText() ([]byte, error) {
102103
func (i *Int8) SetValid(n int8) {
103104
i.Int8 = n
104105
i.Valid = true
106+
i.set = true
105107
}
106108

107109
// Ptr returns a pointer to this Int8's value, or a nil pointer if this Int8 is null.
@@ -119,6 +121,7 @@ func (i Int8) IsZero() bool {
119121

120122
// Scan implements the Scanner interface.
121123
func (i *Int8) Scan(value interface{}) error {
124+
i.set = true
122125
if value == nil {
123126
i.Int8, i.Valid = 0, false
124127
return nil

json.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"errors"
88
"fmt"
99

10-
"github.com/volatiletech/null/v8/convert"
10+
"github.com/razor-1/null/v9/convert"
1111
"github.com/volatiletech/randomize"
1212
)
1313

@@ -86,6 +86,7 @@ func (j *JSON) UnmarshalJSON(data []byte) error {
8686

8787
// UnmarshalText implements encoding.TextUnmarshaler.
8888
func (j *JSON) UnmarshalText(text []byte) error {
89+
j.set = true
8990
if text == nil || len(text) == 0 {
9091
j.JSON = nil
9192
j.Valid = false
@@ -131,6 +132,7 @@ func (j JSON) MarshalText() ([]byte, error) {
131132
func (j *JSON) SetValid(n []byte) {
132133
j.JSON = n
133134
j.Valid = true
135+
j.set = true
134136
}
135137

136138
// Ptr returns a pointer to this JSON's value, or a nil pointer if this JSON is null.
@@ -148,6 +150,7 @@ func (j JSON) IsZero() bool {
148150

149151
// Scan implements the Scanner interface.
150152
func (j *JSON) Scan(value interface{}) error {
153+
j.set = true
151154
if value == nil {
152155
j.JSON, j.Valid = []byte{}, false
153156
return nil

0 commit comments

Comments
 (0)