Skip to content

Commit

Permalink
修复ftime sql序列化问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yumaojun03 committed Mar 12, 2020
1 parent 212197c commit 4030c73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 13 additions & 8 deletions types/ftime/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ package ftime

import (
"database/sql/driver"
"errors"
)

// Scan 实现sql的反序列化
func (t Time) Scan(value interface{}) {
switch UsedFormatType {
case TIMESTAMP:
value = t.timestamp()
case TEXT:
value = t.formatText()
func (t *Time) Scan(value interface{}) error {
if t == nil {
return nil
}

switch v := value.(type) {
case int64:
return t.parseTSInt64(v)
case string:
return t.parseTS(v)
default:
value = t.timestamp()
return errors.New("unsupport type")
}
}

// Value 实现sql的序列化
func (t *Time) Value() (driver.Value, error) {
func (t Time) Value() (driver.Value, error) {
switch UsedFormatType {
case TIMESTAMP:
return t.timestamp(), nil
Expand Down
4 changes: 4 additions & 0 deletions types/ftime/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (t Time) formatText() []byte {
func (t Time) timestamp() int64 {
var ts int64

if t.T().IsZero() {
return 0
}

switch UsedTimestampLength {
case Length10:
ts = time.Time(t).Unix()
Expand Down

0 comments on commit 4030c73

Please sign in to comment.