mirror of https://github.com/go-gorm/gorm.git
Fix exception in mysql
This commit is contained in:
parent
e6c953dd4c
commit
d232c69369
12
main_test.go
12
main_test.go
|
@ -25,17 +25,20 @@ type IgnoredEmbedStruct struct {
|
||||||
type Num int64
|
type Num int64
|
||||||
|
|
||||||
func (i *Num) Scan(src interface{}) error {
|
func (i *Num) Scan(src interface{}) error {
|
||||||
v := reflect.ValueOf(src)
|
switch s := src.(type) {
|
||||||
if v.Kind() != reflect.Int64 {
|
case []byte:
|
||||||
return errors.New("Cannot scan NamedInt from " + v.String())
|
case int64:
|
||||||
|
*i = Num(s)
|
||||||
|
default:
|
||||||
|
return errors.New("Cannot scan NamedInt from " + reflect.ValueOf(src).String())
|
||||||
}
|
}
|
||||||
*i = Num(v.Int())
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64 // Id: Primary key
|
Id int64 // Id: Primary key
|
||||||
Age int64
|
Age int64
|
||||||
|
UserNum Num
|
||||||
Name string `sql:"size:255"`
|
Name string `sql:"size:255"`
|
||||||
Birthday time.Time // Time
|
Birthday time.Time // Time
|
||||||
CreatedAt time.Time // CreatedAt: Time of record is created, will be insert automatically
|
CreatedAt time.Time // CreatedAt: Time of record is created, will be insert automatically
|
||||||
|
@ -53,7 +56,6 @@ type User struct {
|
||||||
PasswordHash []byte
|
PasswordHash []byte
|
||||||
IgnoreMe int64 `sql:"-"`
|
IgnoreMe int64 `sql:"-"`
|
||||||
IgnoreStringSlice []string `sql:"-"`
|
IgnoreStringSlice []string `sql:"-"`
|
||||||
UserNum Num
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreditCard struct {
|
type CreditCard struct {
|
||||||
|
|
Loading…
Reference in New Issue