Fix exception in mysql

This commit is contained in:
Jinzhu 2014-03-16 10:57:38 +08:00
parent e6c953dd4c
commit d232c69369
1 changed files with 7 additions and 5 deletions

View File

@ -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
@ -53,7 +56,6 @@ type User struct {
PasswordHash []byte
IgnoreMe int64 `sql:"-"`
IgnoreStringSlice []string `sql:"-"`
UserNum Num
}
type CreditCard struct {