package sqltypes import ( "database/sql/driver" "errors" "git.aiterp.net/stufflog3/stufflog3-api/internal/models" "time" ) type NullDate struct { Date models.Date Valid bool } func (n *NullDate) Scan(value interface{}) error { if value == nil { n.Valid = false return nil } switch value := value.(type) { case string: date, err := models.ParseDate(value) if err != nil { return err } n.Date = date n.Valid = true case time.Time: n.Date = models.Date{value.Year(), int(value.Month()), value.Day()} n.Valid = true default: return errors.New("invalid type") } return nil } func (n NullDate) Value() (driver.Value, error) { if !n.Valid { return nil, nil } return n.Date.String(), nil }