gf/os/gtime/gtime_sql.go

29 lines
595 B
Go
Raw Normal View History

2021-03-13 14:07:22 +08:00
package gtime
import (
"database/sql/driver"
)
2021-09-27 21:27:24 +08:00
// Scan implements interface used by Scan in package database/sql for Scanning value
2021-04-01 09:41:14 +08:00
// from database to local golang variable.
2021-03-13 14:07:22 +08:00
func (t *Time) Scan(value interface{}) error {
2021-03-31 14:07:28 +08:00
if t == nil {
return nil
}
2021-03-13 14:07:22 +08:00
newTime := New(value)
2021-04-01 09:41:14 +08:00
*t = *newTime
2021-03-13 14:07:22 +08:00
return nil
}
2021-04-01 09:41:14 +08:00
// Value is the interface providing the Value method for package database/sql/driver
// for retrieving value from golang variable to database.
2021-03-13 14:07:22 +08:00
func (t *Time) Value() (driver.Value, error) {
2021-03-25 13:38:59 +08:00
if t == nil {
return nil, nil
}
2021-03-31 14:07:28 +08:00
if t.IsZero() {
return nil, nil
}
2021-03-13 14:07:22 +08:00
return t.Time, nil
}