schema/field: add builder per numeric type

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

Reviewed By: alexsn

Differential Revision: D16936906

fbshipit-source-id: 06f5721ed0088107cf42382731f8b7282f22eef7
This commit is contained in:
Ariel Mashraki
2019-08-21 07:58:44 -07:00
committed by Facebook Github Bot
parent 8b345d94bb
commit f519a5465e
14 changed files with 1876 additions and 390 deletions

View File

@@ -97,6 +97,7 @@ func ExampleFieldType() {
SetNillableInt16(1).
SetNillableInt32(1).
SetNillableInt64(1).
SetValidateOptionalInt32(1).
SaveX(ctx)
log.Println("fieldtype created:", ft)

View File

@@ -46,27 +46,30 @@ type FieldType struct {
NillableInt32 *int32 `json:"nillable_int32,omitempty"`
// NillableInt64 holds the value of the "nillable_int64" field.
NillableInt64 *int64 `json:"nillable_int64,omitempty"`
// ValidateOptionalInt32 holds the value of the "validate_optional_int32" field.
ValidateOptionalInt32 int32 `json:"validate_optional_int32,omitempty"`
}
// FromRows scans the sql response data into FieldType.
func (ft *FieldType) FromRows(rows *sql.Rows) error {
var vft struct {
ID int
Int sql.NullInt64
Int8 sql.NullInt64
Int16 sql.NullInt64
Int32 sql.NullInt64
Int64 sql.NullInt64
OptionalInt sql.NullInt64
OptionalInt8 sql.NullInt64
OptionalInt16 sql.NullInt64
OptionalInt32 sql.NullInt64
OptionalInt64 sql.NullInt64
NillableInt sql.NullInt64
NillableInt8 sql.NullInt64
NillableInt16 sql.NullInt64
NillableInt32 sql.NullInt64
NillableInt64 sql.NullInt64
ID int
Int sql.NullInt64
Int8 sql.NullInt64
Int16 sql.NullInt64
Int32 sql.NullInt64
Int64 sql.NullInt64
OptionalInt sql.NullInt64
OptionalInt8 sql.NullInt64
OptionalInt16 sql.NullInt64
OptionalInt32 sql.NullInt64
OptionalInt64 sql.NullInt64
NillableInt sql.NullInt64
NillableInt8 sql.NullInt64
NillableInt16 sql.NullInt64
NillableInt32 sql.NullInt64
NillableInt64 sql.NullInt64
ValidateOptionalInt32 sql.NullInt64
}
// the order here should be the same as in the `fieldtype.Columns`.
if err := rows.Scan(
@@ -86,6 +89,7 @@ func (ft *FieldType) FromRows(rows *sql.Rows) error {
&vft.NillableInt16,
&vft.NillableInt32,
&vft.NillableInt64,
&vft.ValidateOptionalInt32,
); err != nil {
return err
}
@@ -120,6 +124,7 @@ func (ft *FieldType) FromRows(rows *sql.Rows) error {
ft.NillableInt64 = new(int64)
*ft.NillableInt64 = vft.NillableInt64.Int64
}
ft.ValidateOptionalInt32 = int32(vft.ValidateOptionalInt32.Int64)
return nil
}
@@ -130,22 +135,23 @@ func (ft *FieldType) FromResponse(res *gremlin.Response) error {
return err
}
var vft struct {
ID string `json:"id,omitempty"`
Int int `json:"int,omitempty"`
Int8 int8 `json:"int8,omitempty"`
Int16 int16 `json:"int16,omitempty"`
Int32 int32 `json:"int32,omitempty"`
Int64 int64 `json:"int64,omitempty"`
OptionalInt int `json:"optional_int,omitempty"`
OptionalInt8 int8 `json:"optional_int8,omitempty"`
OptionalInt16 int16 `json:"optional_int16,omitempty"`
OptionalInt32 int32 `json:"optional_int32,omitempty"`
OptionalInt64 int64 `json:"optional_int64,omitempty"`
NillableInt *int `json:"nillable_int,omitempty"`
NillableInt8 *int8 `json:"nillable_int8,omitempty"`
NillableInt16 *int16 `json:"nillable_int16,omitempty"`
NillableInt32 *int32 `json:"nillable_int32,omitempty"`
NillableInt64 *int64 `json:"nillable_int64,omitempty"`
ID string `json:"id,omitempty"`
Int int `json:"int,omitempty"`
Int8 int8 `json:"int8,omitempty"`
Int16 int16 `json:"int16,omitempty"`
Int32 int32 `json:"int32,omitempty"`
Int64 int64 `json:"int64,omitempty"`
OptionalInt int `json:"optional_int,omitempty"`
OptionalInt8 int8 `json:"optional_int8,omitempty"`
OptionalInt16 int16 `json:"optional_int16,omitempty"`
OptionalInt32 int32 `json:"optional_int32,omitempty"`
OptionalInt64 int64 `json:"optional_int64,omitempty"`
NillableInt *int `json:"nillable_int,omitempty"`
NillableInt8 *int8 `json:"nillable_int8,omitempty"`
NillableInt16 *int16 `json:"nillable_int16,omitempty"`
NillableInt32 *int32 `json:"nillable_int32,omitempty"`
NillableInt64 *int64 `json:"nillable_int64,omitempty"`
ValidateOptionalInt32 int32 `json:"validate_optional_int32,omitempty"`
}
if err := vmap.Decode(&vft); err != nil {
return err
@@ -166,6 +172,7 @@ func (ft *FieldType) FromResponse(res *gremlin.Response) error {
ft.NillableInt16 = vft.NillableInt16
ft.NillableInt32 = vft.NillableInt32
ft.NillableInt64 = vft.NillableInt64
ft.ValidateOptionalInt32 = vft.ValidateOptionalInt32
return nil
}
@@ -217,6 +224,7 @@ func (ft *FieldType) String() string {
if v := ft.NillableInt64; v != nil {
buf.WriteString(fmt.Sprintf(", nillable_int64=%v", *v))
}
buf.WriteString(fmt.Sprintf(", validate_optional_int32=%v", ft.ValidateOptionalInt32))
buf.WriteString(")")
return buf.String()
}
@@ -249,44 +257,46 @@ func (ft *FieldTypes) FromResponse(res *gremlin.Response) error {
return err
}
var vft []struct {
ID string `json:"id,omitempty"`
Int int `json:"int,omitempty"`
Int8 int8 `json:"int8,omitempty"`
Int16 int16 `json:"int16,omitempty"`
Int32 int32 `json:"int32,omitempty"`
Int64 int64 `json:"int64,omitempty"`
OptionalInt int `json:"optional_int,omitempty"`
OptionalInt8 int8 `json:"optional_int8,omitempty"`
OptionalInt16 int16 `json:"optional_int16,omitempty"`
OptionalInt32 int32 `json:"optional_int32,omitempty"`
OptionalInt64 int64 `json:"optional_int64,omitempty"`
NillableInt *int `json:"nillable_int,omitempty"`
NillableInt8 *int8 `json:"nillable_int8,omitempty"`
NillableInt16 *int16 `json:"nillable_int16,omitempty"`
NillableInt32 *int32 `json:"nillable_int32,omitempty"`
NillableInt64 *int64 `json:"nillable_int64,omitempty"`
ID string `json:"id,omitempty"`
Int int `json:"int,omitempty"`
Int8 int8 `json:"int8,omitempty"`
Int16 int16 `json:"int16,omitempty"`
Int32 int32 `json:"int32,omitempty"`
Int64 int64 `json:"int64,omitempty"`
OptionalInt int `json:"optional_int,omitempty"`
OptionalInt8 int8 `json:"optional_int8,omitempty"`
OptionalInt16 int16 `json:"optional_int16,omitempty"`
OptionalInt32 int32 `json:"optional_int32,omitempty"`
OptionalInt64 int64 `json:"optional_int64,omitempty"`
NillableInt *int `json:"nillable_int,omitempty"`
NillableInt8 *int8 `json:"nillable_int8,omitempty"`
NillableInt16 *int16 `json:"nillable_int16,omitempty"`
NillableInt32 *int32 `json:"nillable_int32,omitempty"`
NillableInt64 *int64 `json:"nillable_int64,omitempty"`
ValidateOptionalInt32 int32 `json:"validate_optional_int32,omitempty"`
}
if err := vmap.Decode(&vft); err != nil {
return err
}
for _, v := range vft {
*ft = append(*ft, &FieldType{
ID: v.ID,
Int: v.Int,
Int8: v.Int8,
Int16: v.Int16,
Int32: v.Int32,
Int64: v.Int64,
OptionalInt: v.OptionalInt,
OptionalInt8: v.OptionalInt8,
OptionalInt16: v.OptionalInt16,
OptionalInt32: v.OptionalInt32,
OptionalInt64: v.OptionalInt64,
NillableInt: v.NillableInt,
NillableInt8: v.NillableInt8,
NillableInt16: v.NillableInt16,
NillableInt32: v.NillableInt32,
NillableInt64: v.NillableInt64,
ID: v.ID,
Int: v.Int,
Int8: v.Int8,
Int16: v.Int16,
Int32: v.Int32,
Int64: v.Int64,
OptionalInt: v.OptionalInt,
OptionalInt8: v.OptionalInt8,
OptionalInt16: v.OptionalInt16,
OptionalInt32: v.OptionalInt32,
OptionalInt64: v.OptionalInt64,
NillableInt: v.NillableInt,
NillableInt8: v.NillableInt8,
NillableInt16: v.NillableInt16,
NillableInt32: v.NillableInt32,
NillableInt64: v.NillableInt64,
ValidateOptionalInt32: v.ValidateOptionalInt32,
})
}
return nil

View File

@@ -2,6 +2,10 @@
package fieldtype
import (
"github.com/facebookincubator/ent/entc/integration/ent/schema"
)
const (
// Label holds the string label denoting the fieldtype type in the database.
Label = "field_type"
@@ -37,6 +41,8 @@ const (
FieldNillableInt32 = "nillable_int32"
// FieldNillableInt64 holds the string denoting the nillable_int64 vertex property in the database.
FieldNillableInt64 = "nillable_int64"
// FieldValidateOptionalInt32 holds the string denoting the validate_optional_int32 vertex property in the database.
FieldValidateOptionalInt32 = "validate_optional_int32"
// Table holds the table name of the fieldtype in the database.
Table = "field_types"
@@ -60,4 +66,11 @@ var Columns = []string{
FieldNillableInt16,
FieldNillableInt32,
FieldNillableInt64,
FieldValidateOptionalInt32,
}
var (
fields = schema.FieldType{}.Fields()
// ValidateOptionalInt32Validator is a validator for the "validate_optional_int32" field. It is called by the builders before save.
ValidateOptionalInt32Validator = fields[15].Validators()[0].(func(int32) error)
)

View File

@@ -336,6 +336,18 @@ func NillableInt64(v int64) predicate.FieldType {
)
}
// ValidateOptionalInt32 applies equality check predicate on the "validate_optional_int32" field. It's identical to ValidateOptionalInt32EQ.
func ValidateOptionalInt32(v int32) predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldValidateOptionalInt32), v))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.EQ(v))
},
)
}
// IntEQ applies the EQ predicate on the "int" field.
func IntEQ(v int) predicate.FieldType {
return predicate.FieldTypePerDialect(
@@ -2316,6 +2328,146 @@ func NillableInt64NotNil() predicate.FieldType {
)
}
// ValidateOptionalInt32EQ applies the EQ predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32EQ(v int32) predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldValidateOptionalInt32), v))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.EQ(v))
},
)
}
// ValidateOptionalInt32NEQ applies the NEQ predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32NEQ(v int32) predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldValidateOptionalInt32), v))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.NEQ(v))
},
)
}
// ValidateOptionalInt32GT applies the GT predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32GT(v int32) predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldValidateOptionalInt32), v))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.GT(v))
},
)
}
// ValidateOptionalInt32GTE applies the GTE predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32GTE(v int32) predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldValidateOptionalInt32), v))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.GTE(v))
},
)
}
// ValidateOptionalInt32LT applies the LT predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32LT(v int32) predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldValidateOptionalInt32), v))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.LT(v))
},
)
}
// ValidateOptionalInt32LTE applies the LTE predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32LTE(v int32) predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldValidateOptionalInt32), v))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.LTE(v))
},
)
}
// ValidateOptionalInt32In applies the In predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32In(vs ...int32) predicate.FieldType {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(vs) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldValidateOptionalInt32), v...))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.Within(v...))
},
)
}
// ValidateOptionalInt32NotIn applies the NotIn predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32NotIn(vs ...int32) predicate.FieldType {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
}
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(vs) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldValidateOptionalInt32), v...))
},
func(t *dsl.Traversal) {
t.Has(Label, FieldValidateOptionalInt32, p.Without(v...))
},
)
}
// ValidateOptionalInt32IsNil applies the IsNil predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32IsNil() predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.IsNull(s.C(FieldValidateOptionalInt32)))
},
func(t *dsl.Traversal) {
t.HasLabel(Label).HasNot(FieldValidateOptionalInt32)
},
)
}
// ValidateOptionalInt32NotNil applies the NotNil predicate on the "validate_optional_int32" field.
func ValidateOptionalInt32NotNil() predicate.FieldType {
return predicate.FieldTypePerDialect(
func(s *sql.Selector) {
s.Where(sql.NotNull(s.C(FieldValidateOptionalInt32)))
},
func(t *dsl.Traversal) {
t.HasLabel(Label).Has(FieldValidateOptionalInt32)
},
)
}
// And groups list of predicates with the AND operator between them.
func And(predicates ...predicate.FieldType) predicate.FieldType {
return predicate.FieldTypePerDialect(

View File

@@ -5,6 +5,7 @@ package ent
import (
"context"
"errors"
"fmt"
"strconv"
"github.com/facebookincubator/ent/entc/integration/ent/fieldtype"
@@ -19,21 +20,22 @@ import (
// FieldTypeCreate is the builder for creating a FieldType entity.
type FieldTypeCreate struct {
config
int *int
int8 *int8
int16 *int16
int32 *int32
int64 *int64
optional_int *int
optional_int8 *int8
optional_int16 *int16
optional_int32 *int32
optional_int64 *int64
nillable_int *int
nillable_int8 *int8
nillable_int16 *int16
nillable_int32 *int32
nillable_int64 *int64
int *int
int8 *int8
int16 *int16
int32 *int32
int64 *int64
optional_int *int
optional_int8 *int8
optional_int16 *int16
optional_int32 *int32
optional_int64 *int64
nillable_int *int
nillable_int8 *int8
nillable_int16 *int16
nillable_int32 *int32
nillable_int64 *int64
validate_optional_int32 *int32
}
// SetInt sets the int field.
@@ -206,6 +208,20 @@ func (ftc *FieldTypeCreate) SetNillableNillableInt64(i *int64) *FieldTypeCreate
return ftc
}
// SetValidateOptionalInt32 sets the validate_optional_int32 field.
func (ftc *FieldTypeCreate) SetValidateOptionalInt32(i int32) *FieldTypeCreate {
ftc.validate_optional_int32 = &i
return ftc
}
// SetNillableValidateOptionalInt32 sets the validate_optional_int32 field if the given value is not nil.
func (ftc *FieldTypeCreate) SetNillableValidateOptionalInt32(i *int32) *FieldTypeCreate {
if i != nil {
ftc.SetValidateOptionalInt32(*i)
}
return ftc
}
// Save creates the FieldType in the database.
func (ftc *FieldTypeCreate) Save(ctx context.Context) (*FieldType, error) {
if ftc.int == nil {
@@ -223,6 +239,11 @@ func (ftc *FieldTypeCreate) Save(ctx context.Context) (*FieldType, error) {
if ftc.int64 == nil {
return nil, errors.New("ent: missing required field \"int64\"")
}
if ftc.validate_optional_int32 != nil {
if err := fieldtype.ValidateOptionalInt32Validator(*ftc.validate_optional_int32); err != nil {
return nil, fmt.Errorf("ent: validator failed for field \"validate_optional_int32\": %v", err)
}
}
switch ftc.driver.Dialect() {
case dialect.MySQL, dialect.SQLite:
return ftc.sqlSave(ctx)
@@ -312,6 +333,10 @@ func (ftc *FieldTypeCreate) sqlSave(ctx context.Context) (*FieldType, error) {
builder.Set(fieldtype.FieldNillableInt64, *ftc.nillable_int64)
ft.NillableInt64 = ftc.nillable_int64
}
if ftc.validate_optional_int32 != nil {
builder.Set(fieldtype.FieldValidateOptionalInt32, *ftc.validate_optional_int32)
ft.ValidateOptionalInt32 = *ftc.validate_optional_int32
}
query, args := builder.Query()
if err := tx.Exec(ctx, query, args, &res); err != nil {
return nil, rollback(tx, err)
@@ -390,5 +415,8 @@ func (ftc *FieldTypeCreate) gremlin() *dsl.Traversal {
if ftc.nillable_int64 != nil {
v.Property(dsl.Single, fieldtype.FieldNillableInt64, *ftc.nillable_int64)
}
if ftc.validate_optional_int32 != nil {
v.Property(dsl.Single, fieldtype.FieldValidateOptionalInt32, *ftc.validate_optional_int32)
}
return v.ValueMap(true)
}

View File

@@ -20,22 +20,23 @@ import (
// FieldTypeUpdate is the builder for updating FieldType entities.
type FieldTypeUpdate struct {
config
int *int
int8 *int8
int16 *int16
int32 *int32
int64 *int64
optional_int *int
optional_int8 *int8
optional_int16 *int16
optional_int32 *int32
optional_int64 *int64
nillable_int *int
nillable_int8 *int8
nillable_int16 *int16
nillable_int32 *int32
nillable_int64 *int64
predicates []predicate.FieldType
int *int
int8 *int8
int16 *int16
int32 *int32
int64 *int64
optional_int *int
optional_int8 *int8
optional_int16 *int16
optional_int32 *int32
optional_int64 *int64
nillable_int *int
nillable_int8 *int8
nillable_int16 *int16
nillable_int32 *int32
nillable_int64 *int64
validate_optional_int32 *int32
predicates []predicate.FieldType
}
// Where adds a new predicate for the builder.
@@ -214,8 +215,27 @@ func (ftu *FieldTypeUpdate) SetNillableNillableInt64(i *int64) *FieldTypeUpdate
return ftu
}
// SetValidateOptionalInt32 sets the validate_optional_int32 field.
func (ftu *FieldTypeUpdate) SetValidateOptionalInt32(i int32) *FieldTypeUpdate {
ftu.validate_optional_int32 = &i
return ftu
}
// SetNillableValidateOptionalInt32 sets the validate_optional_int32 field if the given value is not nil.
func (ftu *FieldTypeUpdate) SetNillableValidateOptionalInt32(i *int32) *FieldTypeUpdate {
if i != nil {
ftu.SetValidateOptionalInt32(*i)
}
return ftu
}
// Save executes the query and returns the number of rows/vertices matched by this operation.
func (ftu *FieldTypeUpdate) Save(ctx context.Context) (int, error) {
if ftu.validate_optional_int32 != nil {
if err := fieldtype.ValidateOptionalInt32Validator(*ftu.validate_optional_int32); err != nil {
return 0, fmt.Errorf("ent: validator failed for field \"validate_optional_int32\": %v", err)
}
}
switch ftu.driver.Dialect() {
case dialect.MySQL, dialect.SQLite:
return ftu.sqlSave(ctx)
@@ -340,6 +360,10 @@ func (ftu *FieldTypeUpdate) sqlSave(ctx context.Context) (n int, err error) {
update = true
builder.Set(fieldtype.FieldNillableInt64, *ftu.nillable_int64)
}
if ftu.validate_optional_int32 != nil {
update = true
builder.Set(fieldtype.FieldValidateOptionalInt32, *ftu.validate_optional_int32)
}
if update {
query, args := builder.Query()
if err := tx.Exec(ctx, query, args, &res); err != nil {
@@ -417,6 +441,9 @@ func (ftu *FieldTypeUpdate) gremlin() *dsl.Traversal {
if ftu.nillable_int64 != nil {
v.Property(dsl.Single, fieldtype.FieldNillableInt64, *ftu.nillable_int64)
}
if ftu.validate_optional_int32 != nil {
v.Property(dsl.Single, fieldtype.FieldValidateOptionalInt32, *ftu.validate_optional_int32)
}
v.Count()
trs = append(trs, v)
return dsl.Join(trs...)
@@ -425,22 +452,23 @@ func (ftu *FieldTypeUpdate) gremlin() *dsl.Traversal {
// FieldTypeUpdateOne is the builder for updating a single FieldType entity.
type FieldTypeUpdateOne struct {
config
id string
int *int
int8 *int8
int16 *int16
int32 *int32
int64 *int64
optional_int *int
optional_int8 *int8
optional_int16 *int16
optional_int32 *int32
optional_int64 *int64
nillable_int *int
nillable_int8 *int8
nillable_int16 *int16
nillable_int32 *int32
nillable_int64 *int64
id string
int *int
int8 *int8
int16 *int16
int32 *int32
int64 *int64
optional_int *int
optional_int8 *int8
optional_int16 *int16
optional_int32 *int32
optional_int64 *int64
nillable_int *int
nillable_int8 *int8
nillable_int16 *int16
nillable_int32 *int32
nillable_int64 *int64
validate_optional_int32 *int32
}
// SetInt sets the int field.
@@ -613,8 +641,27 @@ func (ftuo *FieldTypeUpdateOne) SetNillableNillableInt64(i *int64) *FieldTypeUpd
return ftuo
}
// SetValidateOptionalInt32 sets the validate_optional_int32 field.
func (ftuo *FieldTypeUpdateOne) SetValidateOptionalInt32(i int32) *FieldTypeUpdateOne {
ftuo.validate_optional_int32 = &i
return ftuo
}
// SetNillableValidateOptionalInt32 sets the validate_optional_int32 field if the given value is not nil.
func (ftuo *FieldTypeUpdateOne) SetNillableValidateOptionalInt32(i *int32) *FieldTypeUpdateOne {
if i != nil {
ftuo.SetValidateOptionalInt32(*i)
}
return ftuo
}
// Save executes the query and returns the updated entity.
func (ftuo *FieldTypeUpdateOne) Save(ctx context.Context) (*FieldType, error) {
if ftuo.validate_optional_int32 != nil {
if err := fieldtype.ValidateOptionalInt32Validator(*ftuo.validate_optional_int32); err != nil {
return nil, fmt.Errorf("ent: validator failed for field \"validate_optional_int32\": %v", err)
}
}
switch ftuo.driver.Dialect() {
case dialect.MySQL, dialect.SQLite:
return ftuo.sqlSave(ctx)
@@ -757,6 +804,11 @@ func (ftuo *FieldTypeUpdateOne) sqlSave(ctx context.Context) (ft *FieldType, err
builder.Set(fieldtype.FieldNillableInt64, *ftuo.nillable_int64)
ft.NillableInt64 = ftuo.nillable_int64
}
if ftuo.validate_optional_int32 != nil {
update = true
builder.Set(fieldtype.FieldValidateOptionalInt32, *ftuo.validate_optional_int32)
ft.ValidateOptionalInt32 = *ftuo.validate_optional_int32
}
if update {
query, args := builder.Query()
if err := tx.Exec(ctx, query, args, &res); err != nil {
@@ -835,6 +887,9 @@ func (ftuo *FieldTypeUpdateOne) gremlin(id string) *dsl.Traversal {
if ftuo.nillable_int64 != nil {
v.Property(dsl.Single, fieldtype.FieldNillableInt64, *ftuo.nillable_int64)
}
if ftuo.validate_optional_int32 != nil {
v.Property(dsl.Single, fieldtype.FieldValidateOptionalInt32, *ftuo.validate_optional_int32)
}
v.ValueMap(true)
trs = append(trs, v)
return dsl.Join(trs...)

View File

@@ -65,6 +65,7 @@ var (
{Name: "nillable_int16", Type: field.TypeInt16, Nullable: true},
{Name: "nillable_int32", Type: field.TypeInt32, Nullable: true},
{Name: "nillable_int64", Type: field.TypeInt64, Nullable: true},
{Name: "validate_optional_int32", Type: field.TypeInt32, Nullable: true},
}
// FieldTypesTable holds the schema information for the "field_types" table.
FieldTypesTable = &schema.Table{

View File

@@ -29,5 +29,8 @@ func (FieldType) Fields() []ent.Field {
field.Int16("nillable_int16").Optional().Nillable(),
field.Int32("nillable_int32").Optional().Nillable(),
field.Int64("nillable_int64").Optional().Nillable(),
field.Int32("validate_optional_int32").
Optional().
Max(100),
}
}