Skip to content

Commit

Permalink
Fix exception in mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Mar 16, 2014
1 parent e6c953d commit d232c69
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ type IgnoredEmbedStruct struct {
type Num int64

func (i *Num) Scan(src interface{}) error {
v := reflect.ValueOf(src)
if v.Kind() != reflect.Int64 {
return errors.New("Cannot scan NamedInt from " + v.String())
switch s := src.(type) {
case []byte:
case int64:
*i = Num(s)
default:
return errors.New("Cannot scan NamedInt from " + reflect.ValueOf(src).String())
}
*i = Num(v.Int())
return nil
}

type User struct {
Id int64 // Id: Primary key
Age int64
UserNum Num
Name string `sql:"size:255"`
Birthday time.Time // Time
CreatedAt time.Time // CreatedAt: Time of record is created, will be insert automatically
Expand All @@ -53,7 +56,6 @@ type User struct {
PasswordHash []byte
IgnoreMe int64 `sql:"-"`
IgnoreStringSlice []string `sql:"-"`
UserNum Num
}

type CreditCard struct {
Expand Down

0 comments on commit d232c69

Please sign in to comment.