-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This matches NullBool, NullFloat64, and NullInt64. Fixes #30305 Change-Id: I79bfcf04a3d43b965d2a3159b0ac22f3e8084a53 Reviewed-on: https://go-review.googlesource.com/c/go/+/170699 Run-TryBot: Daniel Theophanes <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
- Loading branch information
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,6 +286,32 @@ func (n NullBool) Value() (driver.Value, error) { | |
return n.Bool, nil | ||
} | ||
|
||
// NullTime represents a time.Time that may be null. | ||
// NullTime implements the Scanner interface so | ||
// it can be used as a scan destination, similar to NullString. | ||
type NullTime struct { | ||
Time time.Time | ||
Valid bool // Valid is true if Time is not NULL | ||
} | ||
|
||
// Scan implements the Scanner interface. | ||
func (n *NullTime) Scan(value interface{}) error { | ||
if value == nil { | ||
n.Time, n.Valid = time.Time{}, false | ||
return nil | ||
} | ||
n.Valid = true | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ianlancetaylor
Member
|
||
return convertAssign(&n.Time, value) | ||
} | ||
|
||
// Value implements the driver Valuer interface. | ||
func (n NullTime) Value() (driver.Value, error) { | ||
if !n.Valid { | ||
return nil, nil | ||
} | ||
return n.Time, nil | ||
} | ||
|
||
// Scanner is an interface used by Scan. | ||
type Scanner interface { | ||
// Scan assigns a value from a database driver. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NullTime is true if assertion is failed: for example Scan(int64(42))
error is "unsupported Scan, storing driver.Value type int64 into type *time.Time", but time is already true.
Is this good?