Categorygithub.com/lucencytech/null
modulepackage
8.0.0+incompatible
Repository: https://github.com/lucencytech/null.git
Documentation: pkg.go.dev

# README

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:

Null used to be versioned with gopkg.in, so once you upgrade to v8 and beyond please stop using gopkg.in and ensure you're using vgo, dep or vendoring to version null.

go get -u "github.com/volatiletech/null"

null package

import "github.com/volatiletech/null"

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

# Packages

No description provided by the author

# Functions

BoolFrom creates a new Bool that will always be valid.
BoolFromPtr creates a new Bool that will be null if f is nil.
ByteFrom creates a new Byte that will always be valid.
ByteFromPtr creates a new Byte that be null if i is nil.
BytesFrom creates a new Bytes that will be invalid if nil.
BytesFromPtr creates a new Bytes that will be invalid if nil.
Float32From creates a new Float32 that will always be valid.
Float32FromPtr creates a new Float32 that be null if f is nil.
Float64From creates a new Float64 that will always be valid.
Float64FromPtr creates a new Float64 that be null if f is nil.
Int16From creates a new Int16 that will always be valid.
Int16FromPtr creates a new Int16 that be null if i is nil.
Int32From creates a new Int32 that will always be valid.
Int32FromPtr creates a new Int32 that be null if i is nil.
Int64From creates a new Int64 that will always be valid.
Int64FromPtr creates a new Int64 that be null if i is nil.
Int8From creates a new Int8 that will always be valid.
Int8FromPtr creates a new Int8 that be null if i is nil.
IntFrom creates a new Int that will always be valid.
IntFromPtr creates a new Int that be null if i is nil.
JSONFrom creates a new JSON that will be invalid if nil.
JSONFromPtr creates a new JSON that will be invalid if nil.
NewBool creates a new Bool.
NewByte creates a new Byte.
NewBytes creates a new Bytes.
NewFloat32 creates a new Float32.
NewFloat64 creates a new Float64.
NewInt creates a new Int.
NewInt16 creates a new Int16.
NewInt32 creates a new Int32.
NewInt64 creates a new Int64.
NewInt8 creates a new Int8.
NewJSON creates a new JSON.
NewString creates a new String.
NewTime creates a new Time.
NewUint creates a new Uint.
NewUint16 creates a new Uint16.
NewUint32 creates a new Uint32.
NewUint64 creates a new Uint64.
NewUint8 creates a new Uint8.
StringFrom creates a new String that will never be blank.
StringFromPtr creates a new String that be null if s is nil.
TimeFrom creates a new Time that will always be valid.
TimeFromPtr creates a new Time that will be null if t is nil.
Uint16From creates a new Uint16 that will always be valid.
Uint16FromPtr creates a new Uint16 that be null if i is nil.
Uint32From creates a new Uint32 that will always be valid.
Uint32FromPtr creates a new Uint32 that be null if i is nil.
Uint64From creates a new Uint64 that will always be valid.
Uint64FromPtr creates a new Uint64 that be null if i is nil.
Uint8From creates a new Uint8 that will always be valid.
Uint8FromPtr creates a new Uint8 that be null if i is nil.
UintFrom creates a new Uint that will always be valid.
UintFromPtr creates a new Uint that be null if i is nil.

# Variables

NullBytes is a global byte slice of JSON null.

# Structs

Bool is a nullable bool.
Byte is an nullable int.
Bytes is a nullable []byte.
Float32 is a nullable float32.
Float64 is a nullable float64.
Int is an nullable int.
Int16 is an nullable int16.
Int32 is an nullable int32.
Int64 is an nullable int64.
Int8 is an nullable int8.
JSON is a nullable []byte.
String is a nullable string.
Time is a nullable time.Time.
Uint is an nullable uint.
Uint16 is an nullable uint16.
Uint32 is an nullable uint32.
Uint64 is an nullable uint64.
Uint8 is an nullable uint8.