Skip to content

Commit

Permalink
Implement sql.Scanner and driver.Value interfaces for coinbase.Time t…
Browse files Browse the repository at this point in the history
…ype (#102)
  • Loading branch information
sknr authored May 17, 2021
1 parent 67d3834 commit f37f1dd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions time.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package coinbasepro

import (
"database/sql/driver"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -64,3 +65,18 @@ func (t Time) MarshalJSON() ([]byte, error) {
func (t *Time) Time() time.Time {
return time.Time(*t)
}

// Scan implements the sql.Scanner interface for database deserialization.
func (t *Time) Scan(value interface{}) error {
timeValue, ok := value.(time.Time)
if !ok {
return fmt.Errorf("failed to deserialize time: %#v", value)
}
*t = Time(timeValue)
return nil
}

// Value implements the driver.Valuer interface for database serialization.
func (t Time) Value() (driver.Value, error) {
return t.Time(), nil
}

0 comments on commit f37f1dd

Please sign in to comment.