File tree 17 files changed +84
-40
lines changed
17 files changed +84
-40
lines changed Original file line number Diff line number Diff line change @@ -11,24 +11,24 @@ type Bool struct {
11
11
nullValue * sql.NullBool
12
12
}
13
13
14
- func (s Bool ) String () string {
14
+ func (s * Bool ) String () string {
15
15
if s .nullValue != nil {
16
16
return fmt .Sprint (s .nullValue .Bool )
17
17
}
18
18
19
19
return ""
20
20
}
21
21
22
- func NewBool (value bool ) Bool {
23
- return Bool {
22
+ func NewBool (value bool ) * Bool {
23
+ return & Bool {
24
24
nullValue : & sql.NullBool {
25
25
Valid : true ,
26
26
Bool : value ,
27
27
},
28
28
}
29
29
}
30
30
31
- func (s Bool ) Get () bool {
31
+ func (s * Bool ) Get () bool {
32
32
if s .nullValue != nil {
33
33
return s .nullValue .Bool
34
34
}
@@ -45,6 +45,11 @@ func (s *Bool) Value() (driver.Value, error) {
45
45
}
46
46
47
47
func (s * Bool ) Scan (value any ) error {
48
+ s .nullValue = & sql.NullBool {
49
+ Bool : false ,
50
+ Valid : false ,
51
+ }
52
+
48
53
if err := s .nullValue .Scan (value ); err != nil {
49
54
return err
50
55
}
@@ -62,6 +67,7 @@ func (s *Bool) UnmarshalJSON(bytes []byte) error {
62
67
if err := json .Unmarshal (bytes , & s .nullValue .Bool ); err != nil {
63
68
return err
64
69
}
70
+ s .nullValue .Valid = true
65
71
}
66
72
67
73
return nil
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ func (s Byte) String() string {
19
19
return ""
20
20
}
21
21
22
- func NewByte (value byte ) Byte {
23
- return Byte {
22
+ func NewByte (value byte ) * Byte {
23
+ return & Byte {
24
24
nullValue : & sql.NullByte {
25
25
Valid : true ,
26
26
Byte : value ,
@@ -36,7 +36,7 @@ func (s Byte) Get() byte {
36
36
return 0
37
37
}
38
38
39
- func (s * Byte ) Value () (driver.Value , error ) {
39
+ func (s Byte ) Value () (driver.Value , error ) {
40
40
if s .nullValue != nil {
41
41
return s .nullValue .Value ()
42
42
}
@@ -45,11 +45,12 @@ func (s *Byte) Value() (driver.Value, error) {
45
45
}
46
46
47
47
func (s * Byte ) Scan (value any ) error {
48
- if err := s .nullValue .Scan (value ); err != nil {
49
- return err
48
+ s .nullValue = & sql.NullByte {
49
+ Byte : 0 ,
50
+ Valid : false ,
50
51
}
51
52
52
- return nil
53
+ return s . nullValue . Scan ( value )
53
54
}
54
55
55
56
func (s * Byte ) UnmarshalJSON (bytes []byte ) error {
@@ -62,6 +63,7 @@ func (s *Byte) UnmarshalJSON(bytes []byte) error {
62
63
if err := json .Unmarshal (bytes , & s .nullValue .Byte ); err != nil {
63
64
return err
64
65
}
66
+ s .nullValue .Valid = true
65
67
}
66
68
67
69
return nil
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ func (s Float32) String() string {
19
19
return ""
20
20
}
21
21
22
- func NewFloat32 (value float32 ) Float32 {
23
- return Float32 {
22
+ func NewFloat32 (value float32 ) * Float32 {
23
+ return & Float32 {
24
24
nullValue : & sql.NullFloat64 {
25
25
Valid : true ,
26
26
Float64 : float64 (value ),
@@ -36,7 +36,7 @@ func (s Float32) Get() float32 {
36
36
return 0
37
37
}
38
38
39
- func (s * Float32 ) Value () (driver.Value , error ) {
39
+ func (s Float32 ) Value () (driver.Value , error ) {
40
40
if s .nullValue != nil {
41
41
return s .nullValue .Value ()
42
42
}
@@ -45,6 +45,10 @@ func (s *Float32) Value() (driver.Value, error) {
45
45
}
46
46
47
47
func (s * Float32 ) Scan (value any ) error {
48
+ s .nullValue = & sql.NullFloat64 {
49
+ Valid : false ,
50
+ Float64 : 0 ,
51
+ }
48
52
if err := s .nullValue .Scan (value ); err != nil {
49
53
return err
50
54
}
@@ -62,6 +66,7 @@ func (s *Float32) UnmarshalJSON(bytes []byte) error {
62
66
if err := json .Unmarshal (bytes , & s .nullValue .Float64 ); err != nil {
63
67
return err
64
68
}
69
+ s .nullValue .Valid = true
65
70
}
66
71
67
72
return nil
Original file line number Diff line number Diff line change 8
8
func TestFloat32 (t * testing.T ) {
9
9
testCases := []struct {
10
10
name string
11
- s Float32
11
+ s * Float32
12
12
}{
13
13
{
14
14
name : "Not null marshaller" ,
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ func (s Float64) String() string {
19
19
return ""
20
20
}
21
21
22
- func NewFloat64 (value float64 ) Float64 {
23
- return Float64 {
22
+ func NewFloat64 (value float64 ) * Float64 {
23
+ return & Float64 {
24
24
nullValue : & sql.NullFloat64 {
25
25
Valid : true ,
26
26
Float64 : value ,
@@ -45,6 +45,10 @@ func (s *Float64) Value() (driver.Value, error) {
45
45
}
46
46
47
47
func (s * Float64 ) Scan (value any ) error {
48
+ s .nullValue = & sql.NullFloat64 {
49
+ Valid : false ,
50
+ Float64 : 0 ,
51
+ }
48
52
if err := s .nullValue .Scan (value ); err != nil {
49
53
return err
50
54
}
@@ -62,6 +66,7 @@ func (s *Float64) UnmarshalJSON(bytes []byte) error {
62
66
if err := json .Unmarshal (bytes , & s .nullValue .Float64 ); err != nil {
63
67
return err
64
68
}
69
+ s .nullValue .Valid = true
65
70
}
66
71
67
72
return nil
Original file line number Diff line number Diff line change 8
8
func TestFloat64 (t * testing.T ) {
9
9
testCases := []struct {
10
10
name string
11
- s Float64
11
+ s * Float64
12
12
}{
13
13
{
14
14
name : "Not null marshaller" ,
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ func (s Int) String() string {
19
19
return ""
20
20
}
21
21
22
- func NewInt (value int ) Int {
23
- return Int {
22
+ func NewInt (value int ) * Int {
23
+ return & Int {
24
24
nullValue : & sql.NullInt32 {
25
25
Valid : true ,
26
26
Int32 : int32 (value ),
@@ -36,7 +36,7 @@ func (s Int) Get() int {
36
36
return 0
37
37
}
38
38
39
- func (s * Int ) Value () (driver.Value , error ) {
39
+ func (s Int ) Value () (driver.Value , error ) {
40
40
if s .nullValue != nil {
41
41
return s .nullValue .Value ()
42
42
}
@@ -45,6 +45,10 @@ func (s *Int) Value() (driver.Value, error) {
45
45
}
46
46
47
47
func (s * Int ) Scan (value any ) error {
48
+ s .nullValue = & sql.NullInt32 {
49
+ Int32 : 0 ,
50
+ Valid : false ,
51
+ }
48
52
if err := s .nullValue .Scan (value ); err != nil {
49
53
return err
50
54
}
@@ -62,6 +66,7 @@ func (s *Int) UnmarshalJSON(bytes []byte) error {
62
66
if err := json .Unmarshal (bytes , & s .nullValue .Int32 ); err != nil {
63
67
return err
64
68
}
69
+ s .nullValue .Valid = true
65
70
}
66
71
67
72
return nil
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ func (s Int16) String() string {
19
19
return ""
20
20
}
21
21
22
- func NewInt16 (value int16 ) Int16 {
23
- return Int16 {
22
+ func NewInt16 (value int16 ) * Int16 {
23
+ return & Int16 {
24
24
nullValue : & sql.NullInt16 {
25
25
Valid : true ,
26
26
Int16 : value ,
@@ -36,7 +36,7 @@ func (s Int16) Get() int16 {
36
36
return 0
37
37
}
38
38
39
- func (s * Int16 ) Value () (driver.Value , error ) {
39
+ func (s Int16 ) Value () (driver.Value , error ) {
40
40
if s .nullValue != nil {
41
41
return s .nullValue .Value ()
42
42
}
@@ -45,6 +45,10 @@ func (s *Int16) Value() (driver.Value, error) {
45
45
}
46
46
47
47
func (s * Int16 ) Scan (value any ) error {
48
+ s .nullValue = & sql.NullInt16 {
49
+ Int16 : 0 ,
50
+ Valid : false ,
51
+ }
48
52
if err := s .nullValue .Scan (value ); err != nil {
49
53
return err
50
54
}
@@ -62,6 +66,7 @@ func (s *Int16) UnmarshalJSON(bytes []byte) error {
62
66
if err := json .Unmarshal (bytes , & s .nullValue .Int16 ); err != nil {
63
67
return err
64
68
}
69
+ s .nullValue .Valid = true
65
70
}
66
71
67
72
return nil
Original file line number Diff line number Diff line change 9
9
func TestInt16 (t * testing.T ) {
10
10
testCases := []struct {
11
11
name string
12
- s Int16
12
+ s * Int16
13
13
marshalledBytes []byte
14
14
}{
15
15
{
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ func (s Int32) String() string {
19
19
return ""
20
20
}
21
21
22
- func NewInt32 (value int32 ) Int32 {
23
- return Int32 {
22
+ func NewInt32 (value int32 ) * Int32 {
23
+ return & Int32 {
24
24
nullValue : & sql.NullInt32 {
25
25
Valid : true ,
26
26
Int32 : value ,
@@ -36,7 +36,7 @@ func (s Int32) Get() int32 {
36
36
return 0
37
37
}
38
38
39
- func (s * Int32 ) Value () (driver.Value , error ) {
39
+ func (s Int32 ) Value () (driver.Value , error ) {
40
40
if s .nullValue != nil {
41
41
return s .nullValue .Value ()
42
42
}
@@ -45,6 +45,10 @@ func (s *Int32) Value() (driver.Value, error) {
45
45
}
46
46
47
47
func (s * Int32 ) Scan (value any ) error {
48
+ s .nullValue = & sql.NullInt32 {
49
+ Int32 : 0 ,
50
+ Valid : false ,
51
+ }
48
52
if err := s .nullValue .Scan (value ); err != nil {
49
53
return err
50
54
}
@@ -62,6 +66,7 @@ func (s *Int32) UnmarshalJSON(bytes []byte) error {
62
66
if err := json .Unmarshal (bytes , & s .nullValue .Int32 ); err != nil {
63
67
return err
64
68
}
69
+ s .nullValue .Valid = true
65
70
}
66
71
67
72
return nil
Original file line number Diff line number Diff line change 9
9
func TestInt32 (t * testing.T ) {
10
10
testCases := []struct {
11
11
name string
12
- s Int32
12
+ s * Int32
13
13
marshalledBytes []byte
14
14
}{
15
15
{
Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ func (s Int64) String() string {
19
19
return ""
20
20
}
21
21
22
- func NewInt64 (value int64 ) Int64 {
23
- return Int64 {
22
+ func NewInt64 (value int64 ) * Int64 {
23
+ return & Int64 {
24
24
nullValue : & sql.NullInt64 {
25
25
Valid : true ,
26
26
Int64 : value ,
@@ -36,7 +36,7 @@ func (s Int64) Get() int64 {
36
36
return 0
37
37
}
38
38
39
- func (s * Int64 ) Value () (driver.Value , error ) {
39
+ func (s Int64 ) Value () (driver.Value , error ) {
40
40
if s .nullValue != nil {
41
41
return s .nullValue .Value ()
42
42
}
@@ -62,6 +62,7 @@ func (s *Int64) UnmarshalJSON(bytes []byte) error {
62
62
if err := json .Unmarshal (bytes , & s .nullValue .Int64 ); err != nil {
63
63
return err
64
64
}
65
+ s .nullValue .Valid = true
65
66
}
66
67
67
68
return nil
Original file line number Diff line number Diff line change 9
9
func TestInt64 (t * testing.T ) {
10
10
testCases := []struct {
11
11
name string
12
- s Int64
12
+ s * Int64
13
13
marshalledBytes []byte
14
14
}{
15
15
{
Original file line number Diff line number Diff line change 9
9
func TestInt (t * testing.T ) {
10
10
testCases := []struct {
11
11
name string
12
- s Int
12
+ s * Int
13
13
marshalledBytes []byte
14
14
}{
15
15
{
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ func (s String) String() string {
18
18
return ""
19
19
}
20
20
21
- func NewString (value string ) String {
22
- return String {
21
+ func NewString (value string ) * String {
22
+ return & String {
23
23
nullValue : & sql.NullString {
24
24
Valid : value != "" ,
25
25
String : value ,
@@ -35,7 +35,7 @@ func (s String) Get() string {
35
35
return ""
36
36
}
37
37
38
- func (s * String ) Value () (driver.Value , error ) {
38
+ func (s String ) Value () (driver.Value , error ) {
39
39
if s .nullValue != nil {
40
40
return s .nullValue .Value ()
41
41
}
@@ -44,6 +44,10 @@ func (s *String) Value() (driver.Value, error) {
44
44
}
45
45
46
46
func (s * String ) Scan (value any ) error {
47
+ s .nullValue = & sql.NullString {
48
+ String : "" ,
49
+ Valid : false ,
50
+ }
47
51
if err := s .nullValue .Scan (value ); err != nil {
48
52
return err
49
53
}
@@ -61,6 +65,7 @@ func (s *String) UnmarshalJSON(bytes []byte) error {
61
65
if err := json .Unmarshal (bytes , & s .nullValue .String ); err != nil {
62
66
return err
63
67
}
68
+ s .nullValue .Valid = true
64
69
}
65
70
66
71
return nil
You can’t perform that action at this time.
0 commit comments