Files
threshold/internal/db/timestamp/scanners.go
T

28 lines
600 B
Go
Raw Normal View History

package timestamp
2020-05-27 18:16:43 -04:00
import (
"database/sql/driver"
"errors"
"time"
"google.golang.org/protobuf/types/known/timestamppb"
2020-05-27 18:16:43 -04:00
)
// Scan implements sql.Scanner for protobuf Timestamp.
2020-05-27 18:16:43 -04:00
func (ts *Timestamp) Scan(value interface{}) error {
switch t := value.(type) {
case time.Time:
ts.Timestamp = timestamppb.New(t) // google proto version
2020-05-27 18:16:43 -04:00
default:
return errors.New("Not a protobuf Timestamp")
}
return nil
}
// Scan implements driver.Valuer for protobuf Timestamp.
2020-05-27 18:16:43 -04:00
func (ts *Timestamp) Value() (driver.Value, error) {
if ts == nil {
return nil, nil
}
return ts.Timestamp.AsTime(), nil
2020-05-27 18:16:43 -04:00
}