entc/gen: handle default funcs in runtime tempalte (#1102)

This commit is contained in:
Ariel Mashraki
2020-12-30 13:05:03 +02:00
committed by GitHub
parent 24f6975b9a
commit 6716581ab4
27 changed files with 633 additions and 23 deletions

View File

@@ -208,7 +208,12 @@ func (b *stringBuilder) Default(s string) *stringBuilder {
return b
}
// DefaultFunc sets the default value generating function of the field.
// DefaultFunc sets the function that is applied to set the default value
// of the field on creation. For example:
//
// field.String("cuid").
// DefaultFunc(cuid.New)
//
func (b *stringBuilder) DefaultFunc(fn func() string) *stringBuilder {
b.desc.Default = fn
return b
@@ -490,15 +495,14 @@ func (b *bytesBuilder) Default(v []byte) *bytesBuilder {
return b
}
// DefaultFunc sets the function that is applied to set default value
// DefaultFunc sets the function that is applied to set the default value
// of the field on creation. For example:
//
// field.Bytes("cuid").
// DefaultFunc(cuid.New)
//
func (b *bytesBuilder) DefaultFunc(v func() []byte) *bytesBuilder {
b.desc.Default = v
func (b *bytesBuilder) DefaultFunc(fn func() []byte) *bytesBuilder {
b.desc.Default = fn
return b
}

View File

@@ -183,8 +183,7 @@ func TestBytes(t *testing.T) {
assert.True(t, fd.Info.Nillable)
assert.True(t, fd.Info.ValueScanner())
fd = field.
Bytes("uuid").
fd = field.Bytes("uuid").
GoType(&uuid.UUID{}).
DefaultFunc(func() []byte {
return []byte("{}")