You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
null is a library with reasonable options for dealing with nullable SQL and JSON values
5
5
6
-
There are two packages: `null` and its subpackage `zero`.
6
+
There are two packages: `null` and its subpackage `zero`.
7
7
8
8
Types in `null` will only be considered null on null input, and will JSON encode to `null`. If you need zero and null be considered separate values, use these.
9
9
@@ -14,6 +14,7 @@ Types in `zero` are treated like zero values in Go: blank string input will prod
14
14
- All types implement `sql.Scanner` and `driver.Valuer`, so you can use this library in place of `sql.NullXXX`.
15
15
- All types also implement `json.Marshaler` and `json.Unmarshaler`, so you can marshal them to their native JSON representation.
16
16
- All non-generic types implement `encoding.TextMarshaler`, `encoding.TextUnmarshaler`. A null object's `MarshalText` will return a blank string.
17
+
- All types implement `interface { IsZero() bool }`. Combined with Go 1.24's `,omitzero`, this lets you omit null types from JSON.
17
18
18
19
## null package
19
20
@@ -25,17 +26,17 @@ Nullable string.
25
26
Marshals to JSON null if SQL source data is null. Zero (blank) input will not produce a null String.
26
27
27
28
#### null.Int, null.Int32, null.Int16, null.Byte
28
-
Nullable int64/int32/int16/byte.
29
+
Nullable int64/int32/int16/byte.
29
30
30
31
Marshals to JSON null if SQL source data is null. Zero input will not produce a null Int.
31
32
32
33
#### null.Float
33
-
Nullable float64.
34
+
Nullable float64.
34
35
35
36
Marshals to JSON null if SQL source data is null. Zero input will not produce a null Float.
36
37
37
38
#### null.Bool
38
-
Nullable bool.
39
+
Nullable bool.
39
40
40
41
Marshals to JSON null if SQL source data is null. False input will not produce a null Bool.
41
42
@@ -58,14 +59,14 @@ Nullable string.
58
59
Will marshal to a blank string if null. Blank string input produces a null String. Null values and zero values are considered equivalent.
59
60
60
61
#### zero.Int, zero.Int32, zero.Int16, zero.Byte
61
-
Nullable int64/int32/int16/byte.
62
+
Nullable int64/int32/int16/byte.
62
63
63
-
Will marshal to 0 if null. 0 produces a null Int. Null values and zero values are considered equivalent.
64
+
Will marshal to 0 if null. 0 produces a null Int. Null values and zero values are considered equivalent.
64
65
65
66
#### zero.Float
66
67
Nullable float64.
67
68
68
-
Will marshal to 0.0 if null. 0.0 produces a null Float. Null values and zero values are considered equivalent.
69
+
Will marshal to 0.0 if null. 0.0 produces a null Float. Null values and zero values are considered equivalent.
69
70
70
71
#### zero.Bool
71
72
Nullable bool.
@@ -104,7 +105,8 @@ This package isn't intended to be a catch-all data-wrangling package. It is esse
104
105
- Unmarshaling from JSON `sql.NullXXX` JSON objects (e.g. `{"Int64": 123, "Valid": true}`) is no longer supported. It's unlikely many people used this, but if you need it, use v3.
105
106
106
107
### Bugs
107
-
`json`'s `",omitempty"` struct tag does not work correctly right now. It will never omit a null or empty String. This might be [fixed eventually](https://github.com/golang/go/issues/11939).
108
+
-~~`json`'s `",omitempty"` struct tag does not work correctly right now. It will never omit a null or empty String. This might be [fixed eventually](https://github.com/golang/go/issues/11939).~~
109
+
- As of Go 1.24, you can use `,omitzero` to omit this package's types. Only took 10 years!
0 commit comments