|
1 |
| -## null-extended [](https://godoc.org/github.com/volatiletech/null) [](http://gocover.io/github.com/volatiletech/null) |
| 1 | +## null [](https://godoc.org/github.com/volatiletech/null) [](http://gocover.io/github.com/volatiletech/null) |
2 | 2 |
|
3 |
| -null-extended is a library with reasonable options for dealing with nullable SQL and JSON values |
| 3 | +`null` is a library with reasonable options for dealing with nullable SQL and |
| 4 | +JSON values. |
4 | 5 |
|
5 |
| -Types in `null` will only be considered null on null input, and will JSON encode to `null`. |
| 6 | +Types in `null` will only be considered null on null input, and will JSON |
| 7 | +encode to `null`. |
6 | 8 |
|
7 |
| -All types implement `sql.Scanner` and `driver.Valuer`, so you can use this library in place of `sql.NullXXX`. All types also implement: `encoding.TextMarshaler`, `encoding.TextUnmarshaler`, `json.Marshaler`, `json.Unmarshaler` and `sql.Scanner`. |
| 9 | +All types implement `sql.Scanner` and `driver.Valuer`, so you can use this |
| 10 | +library in place of `sql.NullXXX`. All types also implement: |
| 11 | +`encoding.TextMarshaler`, `encoding.TextUnmarshaler`, `json.Marshaler`, |
| 12 | +`json.Unmarshaler` and `sql.Scanner`. |
8 | 13 |
|
9 | 14 | ---
|
10 | 15 |
|
11 |
| -Install: |
| 16 | +### Installation |
12 | 17 |
|
13 | 18 | Null used to be versioned with gopkg.in, so once you upgrade to v8 and beyond
|
14 |
| -please stop using gopkg.in and ensure you're using `vgo`, `dep` or vendoring |
15 |
| -to version null. |
| 19 | +please stop using gopkg.in and ensure you're using `vgo`, `dep` or vendoring to |
| 20 | +version null. |
| 21 | + |
| 22 | +``` |
| 23 | +go get -u "github.com/volatiletech/null" |
| 24 | +``` |
| 25 | + |
| 26 | +### Usage |
| 27 | + |
| 28 | +The following are all types supported in this package. All types will marshal |
| 29 | +to JSON null if Invalid or SQL source data is null. |
| 30 | + |
| 31 | +| Type | Description | Notes | |
| 32 | +|------|-------------|-------| |
| 33 | +| `null.JSON` | Nullable `[]byte` | Will marshal to JSON null if Invalid. `[]byte{}` input will not produce an Invalid JSON, but `[]byte(nil)` will. This should be used for storing raw JSON in the database. Also has `null.JSON.Marshal` and `null.JSON.Unmarshal` helpers to marshal and unmarshal foreign objects. | |
| 34 | +| `null.Bytes` | Nullable `[]byte` | `[]byte{}` input will not produce an Invalid Bytes, but `[]byte(nil)` will. This should be used for storing binary data (bytes in PSQL for example) in the database. | |
| 35 | +| `null.String` | Nullable `string` | | |
| 36 | +| `null.Byte` | Nullable `byte` | | |
| 37 | +| `null.Bool` | Nullable `bool` | | |
| 38 | +| `null.Time` | Nullable `time.Time | Marshals to JSON null if SQL source data is null. Uses `time.Time`'s marshaler. | |
| 39 | +| `null.Float32` | Nullable `float32` | | |
| 40 | +| `null.Float64` | Nullable `float64` | | |
| 41 | +| `null.Int` | Nullable `int` | | |
| 42 | +| `null.Int8` | Nullable `int8` | | |
| 43 | +| `null.Int16` | Nullable `int16` | | |
| 44 | +| `null.Int32` | Nullable `int32` | | |
| 45 | +| `null.Int64` | Nullable `int64` | | |
| 46 | +| `null.Uint` | Nullable `uint` | | |
| 47 | +| `null.Uint8` | Nullable `uint8` | | |
| 48 | +| `null.Uint16` | Nullable `uint16` | | |
| 49 | +| `null.Uint32` | Nullable `int32` | | |
| 50 | +| `null.Int64` | Nullable `uint64` | | | |
16 | 51 |
|
17 |
| -`go get -u "github.com/volatiletech/null"` |
18 |
| - |
19 |
| -### null package |
20 |
| - |
21 |
| -`import "github.com/volatiletech/null"` |
22 |
| - |
23 |
| -The following are all types supported in this package. All types will marshal to JSON null if Invalid or SQL source data is null. |
24 |
| - |
25 |
| -#### null.JSON |
26 |
| -Nullable []byte. |
27 |
| - |
28 |
| -Will marshal to JSON null if Invalid. []byte{} input will not produce an Invalid JSON, but []byte(nil) will. This should be used for storing raw JSON in the database. |
29 |
| - |
30 |
| -Also has `null.JSON.Marshal` and `null.JSON.Unmarshal` helpers to marshal and unmarshal foreign objects. |
31 |
| - |
32 |
| -#### null.Bytes |
33 |
| -Nullable []byte. |
34 |
| - |
35 |
| -[]byte{} input will not produce an Invalid Bytes, but []byte(nil) will. This should be used for storing binary data (bytea in PSQL for example) in the database. |
36 |
| - |
37 |
| -#### null.String |
38 |
| -Nullable string. |
39 |
| - |
40 |
| -#### null.Byte |
41 |
| -Nullable byte. |
42 |
| - |
43 |
| -#### null.Bool |
44 |
| -Nullable bool. |
45 |
| - |
46 |
| -#### null.Time |
47 |
| -Nullable time.Time |
48 |
| - |
49 |
| -Marshals to JSON null if SQL source data is null. Uses `time.Time`'s marshaler. |
50 |
| - |
51 |
| -#### null.Float32 |
52 |
| -Nullable float32. |
53 |
| - |
54 |
| -#### null.Float64 |
55 |
| -Nullable float64. |
56 |
| - |
57 |
| -#### null.Int |
58 |
| -Nullable int. |
59 |
| - |
60 |
| -#### null.Int8 |
61 |
| -Nullable int8. |
62 |
| - |
63 |
| -#### null.Int16 |
64 |
| -Nullable int16. |
65 |
| - |
66 |
| -#### null.Int32 |
67 |
| -Nullable int32. |
68 |
| - |
69 |
| -#### null.Int64 |
70 |
| -Nullable int64. |
71 |
| - |
72 |
| -#### null.Uint |
73 |
| -Nullable uint. |
74 |
| - |
75 |
| -#### null.Uint8 |
76 |
| -Nullable uint8. |
77 |
| - |
78 |
| -#### null.Uint16 |
79 |
| -Nullable uint16. |
80 |
| - |
81 |
| -#### null.Uint32 |
82 |
| -Nullable int32. |
| 52 | +### Bugs |
83 | 53 |
|
84 |
| -#### null.Int64 |
85 |
| -Nullable uint64. |
| 54 | +`json`'s `",omitempty"` struct tag does not work correctly right now. It will |
| 55 | +never omit a null or empty String. This might be [fixed |
| 56 | +eventually](https://github.com/golang/go/issues/4357). |
86 | 57 |
|
87 |
| -### Bugs |
88 |
| -`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/4357). |
89 | 58 |
|
90 | 59 | ### License
|
| 60 | + |
91 | 61 | BSD
|
0 commit comments