Skip to content

lefinal/nulls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nulls

made-with-Go Go GitHub go.mod Go version GoReportCard example codecov GitHub issues GitHub code size in bytes

This package uses the principle of NULL-types from the sql-package. However, it also adds JSON (un)marshalling functionality while supporting NULL-values. It's based on the idea of gobuffalo/nulls, but uses native (un)marshalling functionality of the json-package.

Installation

In order to use this package, run:

go get github.com/lefinal/nulls

Predefined Datatypes

  • bool (nulls.Bool)
  • []byte (nulls.ByteSlice)
  • float32 (nulls.Float32)
  • float64 (nulls.Float64)
  • int (nulls.Int)
  • int16 (nulls.Int16)
  • int32 (nulls.Int32)
  • int64 (nulls.Int64)
  • json.RawMessage (nulls.JSONRawMessage)
  • string (nulls.String)
  • time.Time (nulls.Time)

Support for Generics

Any datatype implementing the required interface can be used as Nullable offering the same functionality as predefined ones. If no SQL-support is required, you can also use JSONNullable.

Usage

All datatype feature a value and Valid-field. The latter one is false when a NULL-value is represented. Otherwise, the actual value is found in the value-field. Constructors for creating non-NULL-values are available in the form of for example NewString(str). As the zero-value for the Valid-field is false, you do not need to create NULL-values explicitly.