Giter VIP home page Giter VIP logo

null's Introduction

null GoDoc Coverage

null 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.


Installation

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"

Usage

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

Type Description Notes
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 (bytes 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

null's People

Contributors

guregu avatar nullbio avatar aarondl avatar jedborovik avatar joelkek avatar jseriff avatar justinas avatar minond avatar

Watchers

James Cloos avatar Dave Nelson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.