Gorm: Need `gorm:"nullable"` field attribute

Created on 5 Jun 2016  路  3Comments  路  Source: go-gorm/gorm

Hey.
There is some inconvinience while working with NULL values in database.
Using of sql.NullString or sql.NullInt64 requires extra mapping layer between struct-to-store an struct-to-send (json), because direct marshaling NullString/NullInt64 to json is insane.

All that I need is gorm:"nullable" that will convert 0 and "" to NULL in SQL string before execution.

Most helpful comment

Use pointer of a type to be nullable. like use *string

All 3 comments

Use pointer of a type to be nullable. like use *string

Why use sql.Null* in docs? Anyone have a link to pros/con of using pointer vs sql.Null?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kumarsiva07 picture kumarsiva07  路  3Comments

alanyuen picture alanyuen  路  3Comments

Ganitzsh picture Ganitzsh  路  3Comments

youtwo123 picture youtwo123  路  3Comments

koalacxr picture koalacxr  路  3Comments