Loggest thy stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

46 lines
733 B

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
}