No description
Find a file
Patrick O'brien 41a31fc048 Fix byte scan
2016-11-12 13:40:11 +10:00
convert Add all additional types to zero package 2016-05-18 17:00:15 +10:00
.gitignore initial commit 2014-08-29 00:11:18 +09:00
bool.go Add byte type 2016-11-11 17:15:01 +10:00
bool_test.go Add byte type 2016-11-11 17:15:01 +10:00
byte.go Fix byte scan 2016-11-12 13:40:11 +10:00
byte_test.go Fix byte scan 2016-11-12 13:40:11 +10:00
bytes.go Fix imports for v6 2016-11-12 11:45:55 +10:00
bytes_test.go Removed zero 2016-11-10 17:47:49 +10:00
float32.go Fix imports for v6 2016-11-12 11:45:55 +10:00
float32_test.go Add byte type 2016-11-11 17:15:01 +10:00
float64.go Add byte type 2016-11-11 17:15:01 +10:00
float64_test.go Add byte type 2016-11-11 17:15:01 +10:00
int.go Fix imports for v6 2016-11-12 11:45:55 +10:00
int8.go Fix imports for v6 2016-11-12 11:45:55 +10:00
int8_test.go Add byte type 2016-11-11 17:15:01 +10:00
int16.go Fix imports for v6 2016-11-12 11:45:55 +10:00
int16_test.go Add byte type 2016-11-11 17:15:01 +10:00
int32.go Fix imports for v6 2016-11-12 11:45:55 +10:00
int32_test.go Add byte type 2016-11-11 17:15:01 +10:00
int64.go Add byte type 2016-11-11 17:15:01 +10:00
int64_test.go Add byte type 2016-11-11 17:15:01 +10:00
int_test.go Add byte type 2016-11-11 17:15:01 +10:00
json.go Fix imports for v6 2016-11-12 11:45:55 +10:00
json_test.go Removed zero 2016-11-10 17:47:49 +10:00
LICENSE Update license and readme 2016-09-04 19:18:51 +10:00
README.md Update README.md 2016-11-12 11:57:45 +10:00
string.go Add byte type 2016-11-11 17:15:01 +10:00
string_test.go Fix all unmarshaljson funcs and all types 2016-11-11 01:00:05 +10:00
time.go Add byte type 2016-11-11 17:15:01 +10:00
time_test.go Add byte type 2016-11-11 17:15:01 +10:00
uint.go Fix imports for v6 2016-11-12 11:45:55 +10:00
uint8.go Fix imports for v6 2016-11-12 11:45:55 +10:00
uint8_test.go Add byte type 2016-11-11 17:15:01 +10:00
uint16.go Fix imports for v6 2016-11-12 11:45:55 +10:00
uint16_test.go Add byte type 2016-11-11 17:15:01 +10:00
uint32.go Fix imports for v6 2016-11-12 11:45:55 +10:00
uint32_test.go Add byte type 2016-11-11 17:15:01 +10:00
uint64.go Fix imports for v6 2016-11-12 11:45:55 +10:00
uint64_test.go Add byte type 2016-11-11 17:15:01 +10:00
uint_test.go Add byte type 2016-11-11 17:15:01 +10:00

null-extended GoDoc Coverage

null-extended is a library with reasonable options for dealing with nullable SQL and JSON values

Types in null will only be considered null on null input, and will JSON encode to null.

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.


Install:

go get -u "gopkg.in/nullbio/null.v6"

null package

import "gopkg.in/nullbio/null.v6"

The following are all types supported in this package. All types will marshal to JSON null if Invalid or SQL source data is null.

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.

null.Bytes

Nullable []byte.

[]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.

null.String

Nullable string.

null.Byte

Nullable byte.

null.Bool

Nullable bool.

null.Time

Nullable time.Time

Marshals to JSON null if SQL source data is null. Uses time.Time's marshaler.

null.Float32

Nullable float32.

null.Float64

Nullable float64.

null.Int

Nullable int.

null.Int8

Nullable int8.

null.Int16

Nullable int16.

null.Int32

Nullable int32.

null.Int64

Nullable int64.

null.Uint

Nullable uint.

null.Uint8

Nullable uint8.

null.Uint16

Nullable uint16.

null.Uint32

Nullable int32.

null.Int64

Nullable uint64.

Bugs

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.

License

BSD