mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
entc/gen: wrap nillable fields with custom go-type with sql.nullscanner
This commit is contained in:
committed by
Ariel Mashraki
parent
762e6aeff9
commit
2480b5c0ef
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user