ent/entc: adding NonNegative predicate to signed int types

Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/179

Reviewed By: a8m

Differential Revision: D18617566

fbshipit-source-id: ab5ced97836d05ee5936b39f571063cf618b3481
This commit is contained in:
Alex Snast
2019-11-20 10:10:40 -08:00
committed by Facebook Github Bot
parent 703a6dd039
commit b34c955739
3 changed files with 35 additions and 4 deletions

View File

@@ -90,6 +90,11 @@ func (b *{{ $builder }}) Positive() *{{ $builder }} {
func (b *{{ $builder }}) Negative() *{{ $builder }} {
return b.Max(-1)
}
// NonNegative adds a minimum value validator with the value of 0. Operation fails if the validator fails.
func (b *{{ $builder }}) NonNegative() *{{ $builder }} {
return b.Min(0)
}
{{ end }}
// Default sets the default value of the field.

View File

@@ -158,6 +158,11 @@ func (b *intBuilder) Negative() *intBuilder {
return b.Max(-1)
}
// NonNegative adds a minimum value validator with the value of 0. Operation fails if the validator fails.
func (b *intBuilder) NonNegative() *intBuilder {
return b.Min(0)
}
// Default sets the default value of the field.
func (b *intBuilder) Default(i int) *intBuilder {
b.desc.Default = i
@@ -371,6 +376,11 @@ func (b *int8Builder) Negative() *int8Builder {
return b.Max(-1)
}
// NonNegative adds a minimum value validator with the value of 0. Operation fails if the validator fails.
func (b *int8Builder) NonNegative() *int8Builder {
return b.Min(0)
}
// Default sets the default value of the field.
func (b *int8Builder) Default(i int8) *int8Builder {
b.desc.Default = i
@@ -480,6 +490,11 @@ func (b *int16Builder) Negative() *int16Builder {
return b.Max(-1)
}
// NonNegative adds a minimum value validator with the value of 0. Operation fails if the validator fails.
func (b *int16Builder) NonNegative() *int16Builder {
return b.Min(0)
}
// Default sets the default value of the field.
func (b *int16Builder) Default(i int16) *int16Builder {
b.desc.Default = i
@@ -589,6 +604,11 @@ func (b *int32Builder) Negative() *int32Builder {
return b.Max(-1)
}
// NonNegative adds a minimum value validator with the value of 0. Operation fails if the validator fails.
func (b *int32Builder) NonNegative() *int32Builder {
return b.Min(0)
}
// Default sets the default value of the field.
func (b *int32Builder) Default(i int32) *int32Builder {
b.desc.Default = i
@@ -698,6 +718,11 @@ func (b *int64Builder) Negative() *int64Builder {
return b.Max(-1)
}
// NonNegative adds a minimum value validator with the value of 0. Operation fails if the validator fails.
func (b *int64Builder) NonNegative() *int64Builder {
return b.Min(0)
}
// Default sets the default value of the field.
func (b *int64Builder) Default(i int64) *int64Builder {
b.desc.Default = i