mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/field: add support for setting update default funcs to numeric fields (#1770)
* schema/field:add UpdateDefault to numeric (#1718) * schema/field:fix comment * schema/field: change interface to self type with DefaultFunc/UpdateDefault * schema/field: change interface to self type with DefaultFunc/UpdateDefault * schema/field: change interface to self type with DefaultFunc/UpdateDefault * schema/field: add support for setting update default funcs to numeric fields Co-authored-by: godcong <jumbycc@163.com>
This commit is contained in:
@@ -181,6 +181,18 @@ func (b *intBuilder) DefaultFunc(fn interface{}) *intBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Int("int").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *intBuilder) UpdateDefault(fn interface{}) *intBuilder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *intBuilder) Nillable() *intBuilder {
|
||||
@@ -272,7 +284,7 @@ func (b *intBuilder) Annotations(annotations ...schema.Annotation) *intBuilder {
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *intBuilder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(intType)
|
||||
}
|
||||
return b.desc
|
||||
@@ -340,6 +352,18 @@ func (b *uintBuilder) DefaultFunc(fn interface{}) *uintBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Uint("uint").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *uintBuilder) UpdateDefault(fn interface{}) *uintBuilder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *uintBuilder) Nillable() *uintBuilder {
|
||||
@@ -431,7 +455,7 @@ func (b *uintBuilder) Annotations(annotations ...schema.Annotation) *uintBuilder
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *uintBuilder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(uintType)
|
||||
}
|
||||
return b.desc
|
||||
@@ -509,6 +533,18 @@ func (b *int8Builder) DefaultFunc(fn interface{}) *int8Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Int8("int8").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *int8Builder) UpdateDefault(fn interface{}) *int8Builder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *int8Builder) Nillable() *int8Builder {
|
||||
@@ -600,7 +636,7 @@ func (b *int8Builder) Annotations(annotations ...schema.Annotation) *int8Builder
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *int8Builder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(int8Type)
|
||||
}
|
||||
return b.desc
|
||||
@@ -678,6 +714,18 @@ func (b *int16Builder) DefaultFunc(fn interface{}) *int16Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Int16("int16").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *int16Builder) UpdateDefault(fn interface{}) *int16Builder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *int16Builder) Nillable() *int16Builder {
|
||||
@@ -769,7 +817,7 @@ func (b *int16Builder) Annotations(annotations ...schema.Annotation) *int16Build
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *int16Builder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(int16Type)
|
||||
}
|
||||
return b.desc
|
||||
@@ -847,6 +895,18 @@ func (b *int32Builder) DefaultFunc(fn interface{}) *int32Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Int32("int32").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *int32Builder) UpdateDefault(fn interface{}) *int32Builder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *int32Builder) Nillable() *int32Builder {
|
||||
@@ -938,7 +998,7 @@ func (b *int32Builder) Annotations(annotations ...schema.Annotation) *int32Build
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *int32Builder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(int32Type)
|
||||
}
|
||||
return b.desc
|
||||
@@ -1016,6 +1076,18 @@ func (b *int64Builder) DefaultFunc(fn interface{}) *int64Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Int64("int64").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *int64Builder) UpdateDefault(fn interface{}) *int64Builder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *int64Builder) Nillable() *int64Builder {
|
||||
@@ -1107,7 +1179,7 @@ func (b *int64Builder) Annotations(annotations ...schema.Annotation) *int64Build
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *int64Builder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(int64Type)
|
||||
}
|
||||
return b.desc
|
||||
@@ -1175,6 +1247,18 @@ func (b *uint8Builder) DefaultFunc(fn interface{}) *uint8Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Uint8("uint8").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *uint8Builder) UpdateDefault(fn interface{}) *uint8Builder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *uint8Builder) Nillable() *uint8Builder {
|
||||
@@ -1266,7 +1350,7 @@ func (b *uint8Builder) Annotations(annotations ...schema.Annotation) *uint8Build
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *uint8Builder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(uint8Type)
|
||||
}
|
||||
return b.desc
|
||||
@@ -1334,6 +1418,18 @@ func (b *uint16Builder) DefaultFunc(fn interface{}) *uint16Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Uint16("uint16").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *uint16Builder) UpdateDefault(fn interface{}) *uint16Builder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *uint16Builder) Nillable() *uint16Builder {
|
||||
@@ -1425,7 +1521,7 @@ func (b *uint16Builder) Annotations(annotations ...schema.Annotation) *uint16Bui
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *uint16Builder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(uint16Type)
|
||||
}
|
||||
return b.desc
|
||||
@@ -1493,6 +1589,18 @@ func (b *uint32Builder) DefaultFunc(fn interface{}) *uint32Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Uint32("uint32").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *uint32Builder) UpdateDefault(fn interface{}) *uint32Builder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *uint32Builder) Nillable() *uint32Builder {
|
||||
@@ -1584,7 +1692,7 @@ func (b *uint32Builder) Annotations(annotations ...schema.Annotation) *uint32Bui
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *uint32Builder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(uint32Type)
|
||||
}
|
||||
return b.desc
|
||||
@@ -1652,6 +1760,18 @@ func (b *uint64Builder) DefaultFunc(fn interface{}) *uint64Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// UpdateDefault sets the function that is applied to set default value
|
||||
// of the field on update. For example:
|
||||
//
|
||||
// field.Uint64("uint64").
|
||||
// Default(0).
|
||||
// UpdateDefault(GenNumber),
|
||||
//
|
||||
func (b *uint64Builder) UpdateDefault(fn interface{}) *uint64Builder {
|
||||
b.desc.UpdateDefault = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated struct.
|
||||
func (b *uint64Builder) Nillable() *uint64Builder {
|
||||
@@ -1743,7 +1863,7 @@ func (b *uint64Builder) Annotations(annotations ...schema.Annotation) *uint64Bui
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *uint64Builder) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
if b.desc.Default != nil || b.desc.UpdateDefault != nil {
|
||||
b.desc.checkDefaultFunc(uint64Type)
|
||||
}
|
||||
return b.desc
|
||||
|
||||
Reference in New Issue
Block a user