Fix enum null.String support, add mysql support
This commit is contained in:
parent
d891bcb9f0
commit
0d09921d4c
3 changed files with 40 additions and 4 deletions
randomize
|
@ -158,19 +158,26 @@ func randDate(s *Seed) time.Time {
|
|||
// If canBeNull is true:
|
||||
// The value has the possibility of being null or non-zero at random.
|
||||
func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bool) error {
|
||||
|
||||
kind := field.Kind()
|
||||
typ := field.Type()
|
||||
|
||||
if strings.HasPrefix(fieldType, "enum") {
|
||||
enum, err := randEnumValue(fieldType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
field.Set(reflect.ValueOf(enum))
|
||||
if kind == reflect.Struct {
|
||||
val := null.NewString(enum, rand.Intn(1) == 0)
|
||||
field.Set(reflect.ValueOf(val))
|
||||
} else {
|
||||
field.Set(reflect.ValueOf(enum))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
kind := field.Kind()
|
||||
typ := field.Type()
|
||||
|
||||
var value interface{}
|
||||
var isNull bool
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue