entc/gen: wrap nillable fields with custom go-type with sql.nullscanner

This commit is contained in:
Ariel Mashraki
2021-04-17 10:06:10 +03:00
committed by Ariel Mashraki
parent 762e6aeff9
commit 2480b5c0ef
41 changed files with 181 additions and 95 deletions

View File

@@ -148,3 +148,17 @@ type (
// TxOptions holds the transaction options to be used in DB.BeginTx.
TxOptions = sql.TxOptions
)
// NullScanner represents an sql.Scanner that may be null.
// NullScanner implements the sql.Scanner interface so it can
// be used as a scan destination, similar to the types above.
type NullScanner struct {
S sql.Scanner
Valid bool // Valid is true if the Scan value is not NULL.
}
// Scan implements the Scanner interface.
func (n *NullScanner) Scan(value interface{}) error {
n.Valid = value != nil
return n.S.Scan(value)
}