diff --git a/entc/gen/bindata.go b/entc/gen/bindata.go index bb0491dbe..2056f8cc9 100644 --- a/entc/gen/bindata.go +++ b/entc/gen/bindata.go @@ -1,4 +1,4 @@ -// Package gen Code generated by go-bindata. (@generated) DO NOT EDIT. +// Code generated by go-bindata. (@generated) DO NOT EDIT. // sources: // template/base.tmpl // template/builder/create.tmpl @@ -85,32 +85,21 @@ type bindataFileInfo struct { modTime time.Time } -// Name return file name func (fi bindataFileInfo) Name() string { return fi.name } - -// Size return file size func (fi bindataFileInfo) Size() int64 { return fi.size } - -// Mode return file mode func (fi bindataFileInfo) Mode() os.FileMode { return fi.mode } - -// Mode return file modify time func (fi bindataFileInfo) ModTime() time.Time { return fi.modTime } - -// IsDir return file whether a directory func (fi bindataFileInfo) IsDir() bool { - return fi.mode&os.ModeDir != 0 + return false } - -// Sys return file is sys mode func (fi bindataFileInfo) Sys() interface{} { return nil } @@ -130,7 +119,7 @@ func templateBaseTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/base.tmpl", size: 5021, mode: os.FileMode(420), modTime: time.Unix(1565007749, 0)} + info := bindataFileInfo{name: "template/base.tmpl", size: 5021, mode: os.FileMode(420), modTime: time.Unix(1564913315, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -150,7 +139,7 @@ func templateBuilderCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/create.tmpl", size: 2854, mode: os.FileMode(420), modTime: time.Unix(1566217695, 0)} + info := bindataFileInfo{name: "template/builder/create.tmpl", size: 2854, mode: os.FileMode(420), modTime: time.Unix(1566214133, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -170,7 +159,7 @@ func templateBuilderDeleteTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/delete.tmpl", size: 2044, mode: os.FileMode(420), modTime: time.Unix(1565162769, 0)} + info := bindataFileInfo{name: "template/builder/delete.tmpl", size: 2044, mode: os.FileMode(420), modTime: time.Unix(1565106398, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -190,7 +179,7 @@ func templateBuilderQueryTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/query.tmpl", size: 13220, mode: os.FileMode(420), modTime: time.Unix(1565178244, 0)} + info := bindataFileInfo{name: "template/builder/query.tmpl", size: 13220, mode: os.FileMode(420), modTime: time.Unix(1565165343, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -210,7 +199,7 @@ func templateBuilderSetterTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/setter.tmpl", size: 3185, mode: os.FileMode(420), modTime: time.Unix(1566290736, 0)} + info := bindataFileInfo{name: "template/builder/setter.tmpl", size: 3185, mode: os.FileMode(420), modTime: time.Unix(1566293398, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -230,7 +219,7 @@ func templateBuilderUpdateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/update.tmpl", size: 7371, mode: os.FileMode(420), modTime: time.Unix(1566240455, 0)} + info := bindataFileInfo{name: "template/builder/update.tmpl", size: 7371, mode: os.FileMode(420), modTime: time.Unix(1566293398, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -250,7 +239,7 @@ func templateClientTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/client.tmpl", size: 4352, mode: os.FileMode(420), modTime: time.Unix(1566238093, 0)} + info := bindataFileInfo{name: "template/client.tmpl", size: 4352, mode: os.FileMode(420), modTime: time.Unix(1566224088, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -270,7 +259,7 @@ func templateConfigTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/config.tmpl", size: 1077, mode: os.FileMode(420), modTime: time.Unix(1565007749, 0)} + info := bindataFileInfo{name: "template/config.tmpl", size: 1077, mode: os.FileMode(420), modTime: time.Unix(1564913322, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -290,7 +279,7 @@ func templateContextTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/context.tmpl", size: 523, mode: os.FileMode(420), modTime: time.Unix(1565007749, 0)} + info := bindataFileInfo{name: "template/context.tmpl", size: 523, mode: os.FileMode(420), modTime: time.Unix(1564913326, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -310,7 +299,7 @@ func templateDialectGremlinByTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/by.tmpl", size: 1679, mode: os.FileMode(420), modTime: time.Unix(1564494654, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/by.tmpl", size: 1679, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -330,7 +319,7 @@ func templateDialectGremlinCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/create.tmpl", size: 2567, mode: os.FileMode(420), modTime: time.Unix(1560858191, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/create.tmpl", size: 2567, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -350,7 +339,7 @@ func templateDialectGremlinDecodeTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/decode.tmpl", size: 1924, mode: os.FileMode(420), modTime: time.Unix(1565187546, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/decode.tmpl", size: 1924, mode: os.FileMode(420), modTime: time.Unix(1565180189, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -370,7 +359,7 @@ func templateDialectGremlinDeleteTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/delete.tmpl", size: 541, mode: os.FileMode(420), modTime: time.Unix(1564440681, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/delete.tmpl", size: 541, mode: os.FileMode(420), modTime: time.Unix(1563979564, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -390,7 +379,7 @@ func templateDialectGremlinErrorsTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/errors.tmpl", size: 1608, mode: os.FileMode(420), modTime: time.Unix(1564494654, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/errors.tmpl", size: 1608, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -410,7 +399,7 @@ func templateDialectGremlinGroupTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/group.tmpl", size: 1151, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/group.tmpl", size: 1151, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -430,7 +419,7 @@ func templateDialectGremlinMetaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/meta.tmpl", size: 508, mode: os.FileMode(420), modTime: time.Unix(1564494654, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/meta.tmpl", size: 508, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -450,7 +439,7 @@ func templateDialectGremlinPredicateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/predicate.tmpl", size: 3117, mode: os.FileMode(420), modTime: time.Unix(1565187546, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/predicate.tmpl", size: 3117, mode: os.FileMode(420), modTime: time.Unix(1565183614, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -470,7 +459,7 @@ func templateDialectGremlinQueryTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/query.tmpl", size: 3733, mode: os.FileMode(420), modTime: time.Unix(1564494654, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/query.tmpl", size: 3733, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -490,7 +479,7 @@ func templateDialectGremlinUpdateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/gremlin/update.tmpl", size: 4765, mode: os.FileMode(420), modTime: time.Unix(1566240935, 0)} + info := bindataFileInfo{name: "template/dialect/gremlin/update.tmpl", size: 4765, mode: os.FileMode(420), modTime: time.Unix(1566293398, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -510,7 +499,7 @@ func templateDialectSqlByTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/by.tmpl", size: 753, mode: os.FileMode(420), modTime: time.Unix(1564494654, 0)} + info := bindataFileInfo{name: "template/dialect/sql/by.tmpl", size: 753, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -530,7 +519,7 @@ func templateDialectSqlCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6066, mode: os.FileMode(420), modTime: time.Unix(1565187546, 0)} + info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6066, mode: os.FileMode(420), modTime: time.Unix(1565180278, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -550,7 +539,7 @@ func templateDialectSqlDecodeTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/decode.tmpl", size: 1820, mode: os.FileMode(420), modTime: time.Unix(1566217695, 0)} + info := bindataFileInfo{name: "template/dialect/sql/decode.tmpl", size: 1820, mode: os.FileMode(420), modTime: time.Unix(1566224080, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -570,7 +559,7 @@ func templateDialectSqlDeleteTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/delete.tmpl", size: 489, mode: os.FileMode(420), modTime: time.Unix(1564440681, 0)} + info := bindataFileInfo{name: "template/dialect/sql/delete.tmpl", size: 489, mode: os.FileMode(420), modTime: time.Unix(1563979564, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -590,7 +579,7 @@ func templateDialectSqlErrorsTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/errors.tmpl", size: 771, mode: os.FileMode(420), modTime: time.Unix(1564494654, 0)} + info := bindataFileInfo{name: "template/dialect/sql/errors.tmpl", size: 771, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -610,7 +599,7 @@ func templateDialectSqlGroupTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/group.tmpl", size: 835, mode: os.FileMode(420), modTime: time.Unix(1560858192, 0)} + info := bindataFileInfo{name: "template/dialect/sql/group.tmpl", size: 835, mode: os.FileMode(420), modTime: time.Unix(1558503319, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -630,7 +619,7 @@ func templateDialectSqlMetaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/meta.tmpl", size: 1586, mode: os.FileMode(420), modTime: time.Unix(1564494654, 0)} + info := bindataFileInfo{name: "template/dialect/sql/meta.tmpl", size: 1586, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -650,7 +639,7 @@ func templateDialectSqlPredicateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/predicate.tmpl", size: 4330, mode: os.FileMode(420), modTime: time.Unix(1565187546, 0)} + info := bindataFileInfo{name: "template/dialect/sql/predicate.tmpl", size: 4330, mode: os.FileMode(420), modTime: time.Unix(1565183595, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -670,7 +659,7 @@ func templateDialectSqlQueryTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/query.tmpl", size: 6186, mode: os.FileMode(420), modTime: time.Unix(1564498182, 0)} + info := bindataFileInfo{name: "template/dialect/sql/query.tmpl", size: 6186, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -690,7 +679,7 @@ func templateDialectSqlUpdateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/update.tmpl", size: 11362, mode: os.FileMode(420), modTime: time.Unix(1566240370, 0)} + info := bindataFileInfo{name: "template/dialect/sql/update.tmpl", size: 11362, mode: os.FileMode(420), modTime: time.Unix(1566293398, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -710,7 +699,7 @@ func templateEntTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/ent.tmpl", size: 3369, mode: os.FileMode(420), modTime: time.Unix(1565187546, 0)} + info := bindataFileInfo{name: "template/ent.tmpl", size: 3369, mode: os.FileMode(420), modTime: time.Unix(1565180140, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -730,7 +719,7 @@ func templateExampleTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/example.tmpl", size: 2229, mode: os.FileMode(420), modTime: time.Unix(1566238093, 0)} + info := bindataFileInfo{name: "template/example.tmpl", size: 2229, mode: os.FileMode(420), modTime: time.Unix(1566224088, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -750,7 +739,7 @@ func templateHeaderTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/header.tmpl", size: 240, mode: os.FileMode(420), modTime: time.Unix(1565007749, 0)} + info := bindataFileInfo{name: "template/header.tmpl", size: 240, mode: os.FileMode(420), modTime: time.Unix(1564913919, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -770,7 +759,7 @@ func templateImportTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/import.tmpl", size: 556, mode: os.FileMode(420), modTime: time.Unix(1566238093, 0)} + info := bindataFileInfo{name: "template/import.tmpl", size: 556, mode: os.FileMode(420), modTime: time.Unix(1566224088, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -790,7 +779,7 @@ func templateMetaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/meta.tmpl", size: 2139, mode: os.FileMode(420), modTime: time.Unix(1566217695, 0)} + info := bindataFileInfo{name: "template/meta.tmpl", size: 2139, mode: os.FileMode(420), modTime: time.Unix(1566214133, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -810,7 +799,7 @@ func templateMigrateMigrateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/migrate/migrate.tmpl", size: 1738, mode: os.FileMode(420), modTime: time.Unix(1566238093, 0)} + info := bindataFileInfo{name: "template/migrate/migrate.tmpl", size: 1738, mode: os.FileMode(420), modTime: time.Unix(1566224088, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -830,7 +819,7 @@ func templateMigrateSchemaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/migrate/schema.tmpl", size: 3536, mode: os.FileMode(420), modTime: time.Unix(1566238093, 0)} + info := bindataFileInfo{name: "template/migrate/schema.tmpl", size: 3536, mode: os.FileMode(420), modTime: time.Unix(1566224088, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -850,7 +839,7 @@ func templatePredicateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/predicate.tmpl", size: 1017, mode: os.FileMode(420), modTime: time.Unix(1566238093, 0)} + info := bindataFileInfo{name: "template/predicate.tmpl", size: 1017, mode: os.FileMode(420), modTime: time.Unix(1566224088, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -870,7 +859,7 @@ func templateTxTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/tx.tmpl", size: 3186, mode: os.FileMode(420), modTime: time.Unix(1566238093, 0)} + info := bindataFileInfo{name: "template/tx.tmpl", size: 3186, mode: os.FileMode(420), modTime: time.Unix(1566224088, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -890,7 +879,7 @@ func templateWhereTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/where.tmpl", size: 4681, mode: os.FileMode(420), modTime: time.Unix(1565187546, 0)} + info := bindataFileInfo{name: "template/where.tmpl", size: 4681, mode: os.FileMode(420), modTime: time.Unix(1565182337, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/integration/ent/example_test.go b/entc/integration/ent/example_test.go index cf762eefa..6ea77ad60 100644 --- a/entc/integration/ent/example_test.go +++ b/entc/integration/ent/example_test.go @@ -97,6 +97,7 @@ func ExampleFieldType() { SetNillableInt16(1). SetNillableInt32(1). SetNillableInt64(1). + SetValidateOptionalInt32(1). SaveX(ctx) log.Println("fieldtype created:", ft) diff --git a/entc/integration/ent/fieldtype.go b/entc/integration/ent/fieldtype.go index 890316bf1..239b98817 100644 --- a/entc/integration/ent/fieldtype.go +++ b/entc/integration/ent/fieldtype.go @@ -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 diff --git a/entc/integration/ent/fieldtype/fieldtype.go b/entc/integration/ent/fieldtype/fieldtype.go index ce75b8c13..7883df6a7 100644 --- a/entc/integration/ent/fieldtype/fieldtype.go +++ b/entc/integration/ent/fieldtype/fieldtype.go @@ -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) +) diff --git a/entc/integration/ent/fieldtype/where.go b/entc/integration/ent/fieldtype/where.go index 29cfc73d1..c1eb57577 100644 --- a/entc/integration/ent/fieldtype/where.go +++ b/entc/integration/ent/fieldtype/where.go @@ -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( diff --git a/entc/integration/ent/fieldtype_create.go b/entc/integration/ent/fieldtype_create.go index 7d678c578..3d8b7796a 100644 --- a/entc/integration/ent/fieldtype_create.go +++ b/entc/integration/ent/fieldtype_create.go @@ -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) } diff --git a/entc/integration/ent/fieldtype_update.go b/entc/integration/ent/fieldtype_update.go index 5ca4adf52..9a3fbf640 100644 --- a/entc/integration/ent/fieldtype_update.go +++ b/entc/integration/ent/fieldtype_update.go @@ -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...) diff --git a/entc/integration/ent/migrate/schema.go b/entc/integration/ent/migrate/schema.go index ac972095f..d2e011779 100644 --- a/entc/integration/ent/migrate/schema.go +++ b/entc/integration/ent/migrate/schema.go @@ -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{ diff --git a/entc/integration/ent/schema/fieldtype.go b/entc/integration/ent/schema/fieldtype.go index d23638439..9ba18c729 100644 --- a/entc/integration/ent/schema/fieldtype.go +++ b/entc/integration/ent/schema/fieldtype.go @@ -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), } } diff --git a/entc/load/bindata.go b/entc/load/bindata.go index 9410e0cf4..46f689106 100644 --- a/entc/load/bindata.go +++ b/entc/load/bindata.go @@ -1,4 +1,4 @@ -// Package load Code generated by go-bindata. (@generated) DO NOT EDIT. +// Code generated by go-bindata. (@generated) DO NOT EDIT. // sources: // template/main.tmpl // schema.go @@ -48,32 +48,21 @@ type bindataFileInfo struct { modTime time.Time } -// Name return file name func (fi bindataFileInfo) Name() string { return fi.name } - -// Size return file size func (fi bindataFileInfo) Size() int64 { return fi.size } - -// Mode return file mode func (fi bindataFileInfo) Mode() os.FileMode { return fi.mode } - -// Mode return file modify time func (fi bindataFileInfo) ModTime() time.Time { return fi.modTime } - -// IsDir return file whether a directory func (fi bindataFileInfo) IsDir() bool { - return fi.mode&os.ModeDir != 0 + return false } - -// Sys return file is sys mode func (fi bindataFileInfo) Sys() interface{} { return nil } @@ -93,7 +82,7 @@ func templateMainTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/main.tmpl", size: 647, mode: os.FileMode(420), modTime: time.Unix(1566138012, 0)} + info := bindataFileInfo{name: "template/main.tmpl", size: 647, mode: os.FileMode(420), modTime: time.Unix(1566131522, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -113,7 +102,7 @@ func schemaGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "schema.go", size: 4499, mode: os.FileMode(420), modTime: time.Unix(1566238302, 0)} + info := bindataFileInfo{name: "schema.go", size: 4499, mode: os.FileMode(420), modTime: time.Unix(1566293398, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/schema/field/field.go b/schema/field/field.go index a27dc2bd4..d9a406dd4 100644 --- a/schema/field/field.go +++ b/schema/field/field.go @@ -122,24 +122,6 @@ type Field struct { validators []interface{} } -// Int returns a new Field with type int. -func Int(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt, name: name}} } - -// Int8 returns a new Field with type int8. -func Int8(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt8, name: name}} } - -// Int16 returns a new Field with type int16. -func Int16(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt16, name: name}} } - -// Int32 returns a new Field with type int32. -func Int32(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt32, name: name}} } - -// Int64 returns a new Field with type int64. -func Int64(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt64, name: name}} } - -// Float returns a new Field with type float. -func Float(name string) *floatBuilder { return &floatBuilder{Field{typ: TypeFloat64, name: name}} } - // String returns a new Field with type string. func String(name string) *stringBuilder { return &stringBuilder{Field{typ: TypeString, name: name}} } @@ -189,200 +171,6 @@ func (f Field) Validators() []interface{} { return f.validators } // Tag returns the struct tag of the field. func (f Field) Tag() string { return f.tag } -// intBuilder is the builder for int field. -type intBuilder struct { - Field -} - -// Unique makes the field unique within all vertices of this type. -func (b *intBuilder) Unique() *intBuilder { - b.unique = true - return b -} - -// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. -func (b *intBuilder) Range(i, j int) *intBuilder { - b.validators = append(b.validators, func(v int) error { - if v < i || v > j { - return errors.New("value out of range") - } - return nil - }) - return b -} - -// Min adds a minimum value validator for this field. Operation fails if the validator fails. -func (b *intBuilder) Min(i int) *intBuilder { - b.validators = append(b.validators, func(v int) error { - if v < i { - return errors.New("value out of range") - } - return nil - }) - return b -} - -// Max adds a maximum value validator for this field. Operation fails if the validator fails. -func (b *intBuilder) Max(i int) *intBuilder { - b.validators = append(b.validators, func(v int) error { - if v > i { - return errors.New("value out of range") - } - return nil - }) - return b -} - -// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. -func (b *intBuilder) Positive() *intBuilder { - return b.Min(1) -} - -// Negative adds a maximum value validator with the value of -1. Operation fails if the validator fails. -func (b *intBuilder) Negative() *intBuilder { - return b.Max(-1) -} - -// Default sets the default value of the field. -func (b *intBuilder) Default(i int) *intBuilder { - b.value = i - return b -} - -// Nillable indicates that this field is a nillable. -// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. -func (b *intBuilder) Nillable() *intBuilder { - b.nillable = true - return b -} - -// Comment sets the comment of the field. -func (b *intBuilder) Comment(c string) *intBuilder { - return b -} - -// Optional indicates that this field is optional on create. -// Unlike edges, fields are required by default. -func (b *intBuilder) Optional() *intBuilder { - b.optional = true - return b -} - -// Immutable indicates that this field cannot be updated. -func (b *intBuilder) Immutable() *intBuilder { - b.immutable = true - return b -} - -// StructTag sets the struct tag of the field. -func (b *intBuilder) StructTag(s string) *intBuilder { - b.tag = s - return b -} - -// Validate adds a validator for this field. Operation fails if the validation fails. -func (b *intBuilder) Validate(fn func(int) error) *intBuilder { - b.validators = append(b.validators, fn) - return b -} - -// floatBuilder is the builder for float fields. -type floatBuilder struct { - Field -} - -// Unique makes the field unique within all vertices of this type. -func (b *floatBuilder) Unique() *floatBuilder { - b.unique = true - return b -} - -// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. -func (b *floatBuilder) Range(i, j float64) *floatBuilder { - b.validators = append(b.validators, func(v float64) error { - if v < i || v > j { - return errors.New("value out of range") - } - return nil - }) - return b -} - -// Min adds a minimum value validator for this field. Operation fails if the validator fails. -func (b *floatBuilder) Min(i float64) *floatBuilder { - b.validators = append(b.validators, func(v float64) error { - if v < i { - return errors.New("value out of range") - } - return nil - }) - return b -} - -// Max adds a maximum value validator for this field. Operation fails if the validator fails. -func (b *floatBuilder) Max(i float64) *floatBuilder { - b.validators = append(b.validators, func(v float64) error { - if v > i { - return errors.New("value out of range") - } - return nil - }) - return b -} - -// Positive adds a minimum value validator with the value of 0.000001. Operation fails if the validator fails. -func (b *floatBuilder) Positive() *floatBuilder { - return b.Min(1e-06) -} - -// Negative adds a maximum value validator with the value of -0.000001. Operation fails if the validator fails. -func (b *floatBuilder) Negative() *floatBuilder { - return b.Max(-1e-06) -} - -// Default sets the default value of the field. -func (b *floatBuilder) Default(i float64) *floatBuilder { - b.value = i - return b -} - -// Nillable indicates that this field is a nillable. -// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. -func (b *floatBuilder) Nillable() *floatBuilder { - b.nillable = true - return b -} - -// Comment sets the comment of the field. -func (b *floatBuilder) Comment(c string) *floatBuilder { - return b -} - -// Optional indicates that this field is optional on create. -// Unlike edges, fields are required by default. -func (b *floatBuilder) Optional() *floatBuilder { - b.optional = true - return b -} - -// Immutable indicates that this field cannot be updated. -func (b *floatBuilder) Immutable() *floatBuilder { - b.immutable = true - return b -} - -// StructTag sets the struct tag of the field. -func (b *floatBuilder) StructTag(s string) *floatBuilder { - b.tag = s - return b -} - -// Validate adds a validator for this field. Operation fails if the validation fails. -func (b *floatBuilder) Validate(fn func(float64) error) *floatBuilder { - b.validators = append(b.validators, fn) - return b -} - // stringBuilder is the builder for string fields. type stringBuilder struct { Field diff --git a/schema/field/gen/gen.go b/schema/field/gen/gen.go new file mode 100644 index 000000000..451500765 --- /dev/null +++ b/schema/field/gen/gen.go @@ -0,0 +1,52 @@ +// gen is a codegen cmd for generating numeric build types from template. +package main + +import ( + "bytes" + "go/format" + "io/ioutil" + "log" + "strings" + "text/template" + + "github.com/facebookincubator/ent/schema/field" +) + +func main() { + buf, err := ioutil.ReadFile("gen/numeric.tmpl") + if err != nil { + log.Fatal("reading template file:", err) + } + intTmpl := template.Must(template.New("numeric"). + Funcs(template.FuncMap{"title": strings.Title, "hasPrefix": strings.HasPrefix}). + Parse(string(buf))) + b := &bytes.Buffer{} + if err := intTmpl.Execute(b, struct { + Ints, Floats []field.Type + }{ + Ints: []field.Type{ + field.TypeInt, + field.TypeUint, + field.TypeInt8, + field.TypeInt16, + field.TypeInt32, + field.TypeInt64, + field.TypeUint8, + field.TypeUint16, + field.TypeUint32, + field.TypeUint64, + }, + Floats: []field.Type{ + field.TypeFloat64, + field.TypeFloat32, + }, + }); err != nil { + log.Fatal("executing template:", err) + } + if buf, err = format.Source(b.Bytes()); err != nil { + log.Fatal("formatting output:", err) + } + if err := ioutil.WriteFile("numeric.go", buf, 0644); err != nil { + log.Fatal("writing go file:", err) + } +} diff --git a/schema/field/gen/numeric.tmpl b/schema/field/gen/numeric.tmpl new file mode 100644 index 000000000..8086f294c --- /dev/null +++ b/schema/field/gen/numeric.tmpl @@ -0,0 +1,225 @@ +{{ define "numeric" }} +package field + +import "errors" + +//go:generate go run gen/gen.go + +{{ range $_, $t := $.Ints }} + {{ $title := title $t.String }} + // {{ $title }} returns a new Field with type {{ $t }}. + func {{ $title }}(name string) *{{ $t }}Builder { return &{{ $t }}Builder{Field{typ: Type{{ $title }}, name: name}} } +{{ end }} + +// Float returns a new Field with type float64. +func Float(name string) *float64Builder { return &float64Builder{Field{typ: TypeFloat64, name: name}} } + +// Float32 returns a new Field with type float32. +func Float32(name string) *float32Builder { return &float32Builder{Field{typ: TypeFloat32, name: name}} } + +{{ range $_, $t := $.Ints }} +{{ $builder := printf "%sBuilder" $t }} + +// {{ $builder }} is the builder for {{ $t }} field. +type {{ $builder }} struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *{{ $builder }}) Unique() *{{ $builder }} { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *{{ $builder }}) Range(i, j {{ $t }}) *{{ $builder }} { + b.validators = append(b.validators, func(v {{ $t }}) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *{{ $builder }}) Min(i {{ $t }}) *{{ $builder }} { + b.validators = append(b.validators, func(v {{ $t }}) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *{{ $builder }}) Max(i {{ $t }}) *{{ $builder }} { + b.validators = append(b.validators, func(v {{ $t }}) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *{{ $builder }}) Positive() *{{ $builder }} { + return b.Min(1) +} + +{{ if hasPrefix $t.String "uint" | not }} + // Negative adds a maximum value validator with the value of -1. Operation fails if the validator fails. + func (b *{{ $builder }}) Negative() *{{ $builder }} { + return b.Max(-1) + } +{{ end }} + +// Default sets the default value of the field. +func (b *{{ $builder }}) Default(i {{ $t }}) *{{ $builder }} { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *{{ $builder }}) Nillable() *{{ $builder }} { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *{{ $builder }}) Comment(c string) *{{ $builder }} { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *{{ $builder }}) Optional() *{{ $builder }} { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *{{ $builder }}) Immutable() *{{ $builder }} { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *{{ $builder }}) StructTag(s string) *{{ $builder }} { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *{{ $builder }}) Validate(fn func({{ $t }}) error) *{{ $builder }} { + b.validators = append(b.validators, fn) + return b +} + +{{ end }} + +{{ range $_, $t := $.Floats }} +{{ $builder := printf "%sBuilder" $t }} + +// {{ $builder }} is the builder for float fields. +type {{ $builder }} struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *{{ $builder }}) Unique() *{{ $builder }} { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *{{ $builder }}) Range(i, j {{ $t }}) *{{ $builder }} { + b.validators = append(b.validators, func(v {{ $t }}) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *{{ $builder }}) Min(i {{ $t }}) *{{ $builder }} { + b.validators = append(b.validators, func(v {{ $t }}) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *{{ $builder }}) Max(i {{ $t }}) *{{ $builder }} { + b.validators = append(b.validators, func(v {{ $t }}) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 0.000001. Operation fails if the validator fails. +func (b *{{ $builder }}) Positive() *{{ $builder }} { + return b.Min(1e-06) +} + +// Negative adds a maximum value validator with the value of -0.000001. Operation fails if the validator fails. +func (b *{{ $builder }}) Negative() *{{ $builder }} { + return b.Max(-1e-06) +} + +// Default sets the default value of the field. +func (b *{{ $builder }}) Default(i {{ $t }}) *{{ $builder }} { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *{{ $builder }}) Nillable() *{{ $builder }} { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *{{ $builder }}) Comment(c string) *{{ $builder }} { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *{{ $builder }}) Optional() *{{ $builder }} { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *{{ $builder }}) Immutable() *{{ $builder }} { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *{{ $builder }}) StructTag(s string) *{{ $builder }} { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *{{ $builder }}) Validate(fn func({{ $t }}) error) *{{ $builder }} { + b.validators = append(b.validators, fn) + return b +} +{{ end }} + +{{ end }} \ No newline at end of file diff --git a/schema/field/numeric.go b/schema/field/numeric.go new file mode 100644 index 000000000..56df6f777 --- /dev/null +++ b/schema/field/numeric.go @@ -0,0 +1,1180 @@ +package field + +import "errors" + +//go:generate go run gen/gen.go + +// Int returns a new Field with type int. +func Int(name string) *intBuilder { return &intBuilder{Field{typ: TypeInt, name: name}} } + +// Uint returns a new Field with type uint. +func Uint(name string) *uintBuilder { return &uintBuilder{Field{typ: TypeUint, name: name}} } + +// Int8 returns a new Field with type int8. +func Int8(name string) *int8Builder { return &int8Builder{Field{typ: TypeInt8, name: name}} } + +// Int16 returns a new Field with type int16. +func Int16(name string) *int16Builder { return &int16Builder{Field{typ: TypeInt16, name: name}} } + +// Int32 returns a new Field with type int32. +func Int32(name string) *int32Builder { return &int32Builder{Field{typ: TypeInt32, name: name}} } + +// Int64 returns a new Field with type int64. +func Int64(name string) *int64Builder { return &int64Builder{Field{typ: TypeInt64, name: name}} } + +// Uint8 returns a new Field with type uint8. +func Uint8(name string) *uint8Builder { return &uint8Builder{Field{typ: TypeUint8, name: name}} } + +// Uint16 returns a new Field with type uint16. +func Uint16(name string) *uint16Builder { return &uint16Builder{Field{typ: TypeUint16, name: name}} } + +// Uint32 returns a new Field with type uint32. +func Uint32(name string) *uint32Builder { return &uint32Builder{Field{typ: TypeUint32, name: name}} } + +// Uint64 returns a new Field with type uint64. +func Uint64(name string) *uint64Builder { return &uint64Builder{Field{typ: TypeUint64, name: name}} } + +// Float returns a new Field with type float64. +func Float(name string) *float64Builder { return &float64Builder{Field{typ: TypeFloat64, name: name}} } + +// Float32 returns a new Field with type float32. +func Float32(name string) *float32Builder { return &float32Builder{Field{typ: TypeFloat32, name: name}} } + +// intBuilder is the builder for int field. +type intBuilder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *intBuilder) Unique() *intBuilder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *intBuilder) Range(i, j int) *intBuilder { + b.validators = append(b.validators, func(v int) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *intBuilder) Min(i int) *intBuilder { + b.validators = append(b.validators, func(v int) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *intBuilder) Max(i int) *intBuilder { + b.validators = append(b.validators, func(v int) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *intBuilder) Positive() *intBuilder { + return b.Min(1) +} + +// Negative adds a maximum value validator with the value of -1. Operation fails if the validator fails. +func (b *intBuilder) Negative() *intBuilder { + return b.Max(-1) +} + +// Default sets the default value of the field. +func (b *intBuilder) Default(i int) *intBuilder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *intBuilder) Nillable() *intBuilder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *intBuilder) Comment(c string) *intBuilder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *intBuilder) Optional() *intBuilder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *intBuilder) Immutable() *intBuilder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *intBuilder) StructTag(s string) *intBuilder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *intBuilder) Validate(fn func(int) error) *intBuilder { + b.validators = append(b.validators, fn) + return b +} + +// uintBuilder is the builder for uint field. +type uintBuilder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *uintBuilder) Unique() *uintBuilder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *uintBuilder) Range(i, j uint) *uintBuilder { + b.validators = append(b.validators, func(v uint) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *uintBuilder) Min(i uint) *uintBuilder { + b.validators = append(b.validators, func(v uint) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *uintBuilder) Max(i uint) *uintBuilder { + b.validators = append(b.validators, func(v uint) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *uintBuilder) Positive() *uintBuilder { + return b.Min(1) +} + +// Default sets the default value of the field. +func (b *uintBuilder) Default(i uint) *uintBuilder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *uintBuilder) Nillable() *uintBuilder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *uintBuilder) Comment(c string) *uintBuilder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *uintBuilder) Optional() *uintBuilder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *uintBuilder) Immutable() *uintBuilder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *uintBuilder) StructTag(s string) *uintBuilder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *uintBuilder) Validate(fn func(uint) error) *uintBuilder { + b.validators = append(b.validators, fn) + return b +} + +// int8Builder is the builder for int8 field. +type int8Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *int8Builder) Unique() *int8Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *int8Builder) Range(i, j int8) *int8Builder { + b.validators = append(b.validators, func(v int8) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *int8Builder) Min(i int8) *int8Builder { + b.validators = append(b.validators, func(v int8) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *int8Builder) Max(i int8) *int8Builder { + b.validators = append(b.validators, func(v int8) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *int8Builder) Positive() *int8Builder { + return b.Min(1) +} + +// Negative adds a maximum value validator with the value of -1. Operation fails if the validator fails. +func (b *int8Builder) Negative() *int8Builder { + return b.Max(-1) +} + +// Default sets the default value of the field. +func (b *int8Builder) Default(i int8) *int8Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *int8Builder) Nillable() *int8Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *int8Builder) Comment(c string) *int8Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *int8Builder) Optional() *int8Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *int8Builder) Immutable() *int8Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *int8Builder) StructTag(s string) *int8Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *int8Builder) Validate(fn func(int8) error) *int8Builder { + b.validators = append(b.validators, fn) + return b +} + +// int16Builder is the builder for int16 field. +type int16Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *int16Builder) Unique() *int16Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *int16Builder) Range(i, j int16) *int16Builder { + b.validators = append(b.validators, func(v int16) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *int16Builder) Min(i int16) *int16Builder { + b.validators = append(b.validators, func(v int16) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *int16Builder) Max(i int16) *int16Builder { + b.validators = append(b.validators, func(v int16) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *int16Builder) Positive() *int16Builder { + return b.Min(1) +} + +// Negative adds a maximum value validator with the value of -1. Operation fails if the validator fails. +func (b *int16Builder) Negative() *int16Builder { + return b.Max(-1) +} + +// Default sets the default value of the field. +func (b *int16Builder) Default(i int16) *int16Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *int16Builder) Nillable() *int16Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *int16Builder) Comment(c string) *int16Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *int16Builder) Optional() *int16Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *int16Builder) Immutable() *int16Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *int16Builder) StructTag(s string) *int16Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *int16Builder) Validate(fn func(int16) error) *int16Builder { + b.validators = append(b.validators, fn) + return b +} + +// int32Builder is the builder for int32 field. +type int32Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *int32Builder) Unique() *int32Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *int32Builder) Range(i, j int32) *int32Builder { + b.validators = append(b.validators, func(v int32) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *int32Builder) Min(i int32) *int32Builder { + b.validators = append(b.validators, func(v int32) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *int32Builder) Max(i int32) *int32Builder { + b.validators = append(b.validators, func(v int32) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *int32Builder) Positive() *int32Builder { + return b.Min(1) +} + +// Negative adds a maximum value validator with the value of -1. Operation fails if the validator fails. +func (b *int32Builder) Negative() *int32Builder { + return b.Max(-1) +} + +// Default sets the default value of the field. +func (b *int32Builder) Default(i int32) *int32Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *int32Builder) Nillable() *int32Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *int32Builder) Comment(c string) *int32Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *int32Builder) Optional() *int32Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *int32Builder) Immutable() *int32Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *int32Builder) StructTag(s string) *int32Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *int32Builder) Validate(fn func(int32) error) *int32Builder { + b.validators = append(b.validators, fn) + return b +} + +// int64Builder is the builder for int64 field. +type int64Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *int64Builder) Unique() *int64Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *int64Builder) Range(i, j int64) *int64Builder { + b.validators = append(b.validators, func(v int64) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *int64Builder) Min(i int64) *int64Builder { + b.validators = append(b.validators, func(v int64) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *int64Builder) Max(i int64) *int64Builder { + b.validators = append(b.validators, func(v int64) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *int64Builder) Positive() *int64Builder { + return b.Min(1) +} + +// Negative adds a maximum value validator with the value of -1. Operation fails if the validator fails. +func (b *int64Builder) Negative() *int64Builder { + return b.Max(-1) +} + +// Default sets the default value of the field. +func (b *int64Builder) Default(i int64) *int64Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *int64Builder) Nillable() *int64Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *int64Builder) Comment(c string) *int64Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *int64Builder) Optional() *int64Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *int64Builder) Immutable() *int64Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *int64Builder) StructTag(s string) *int64Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *int64Builder) Validate(fn func(int64) error) *int64Builder { + b.validators = append(b.validators, fn) + return b +} + +// uint8Builder is the builder for uint8 field. +type uint8Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *uint8Builder) Unique() *uint8Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *uint8Builder) Range(i, j uint8) *uint8Builder { + b.validators = append(b.validators, func(v uint8) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *uint8Builder) Min(i uint8) *uint8Builder { + b.validators = append(b.validators, func(v uint8) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *uint8Builder) Max(i uint8) *uint8Builder { + b.validators = append(b.validators, func(v uint8) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *uint8Builder) Positive() *uint8Builder { + return b.Min(1) +} + +// Default sets the default value of the field. +func (b *uint8Builder) Default(i uint8) *uint8Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *uint8Builder) Nillable() *uint8Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *uint8Builder) Comment(c string) *uint8Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *uint8Builder) Optional() *uint8Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *uint8Builder) Immutable() *uint8Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *uint8Builder) StructTag(s string) *uint8Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *uint8Builder) Validate(fn func(uint8) error) *uint8Builder { + b.validators = append(b.validators, fn) + return b +} + +// uint16Builder is the builder for uint16 field. +type uint16Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *uint16Builder) Unique() *uint16Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *uint16Builder) Range(i, j uint16) *uint16Builder { + b.validators = append(b.validators, func(v uint16) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *uint16Builder) Min(i uint16) *uint16Builder { + b.validators = append(b.validators, func(v uint16) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *uint16Builder) Max(i uint16) *uint16Builder { + b.validators = append(b.validators, func(v uint16) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *uint16Builder) Positive() *uint16Builder { + return b.Min(1) +} + +// Default sets the default value of the field. +func (b *uint16Builder) Default(i uint16) *uint16Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *uint16Builder) Nillable() *uint16Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *uint16Builder) Comment(c string) *uint16Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *uint16Builder) Optional() *uint16Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *uint16Builder) Immutable() *uint16Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *uint16Builder) StructTag(s string) *uint16Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *uint16Builder) Validate(fn func(uint16) error) *uint16Builder { + b.validators = append(b.validators, fn) + return b +} + +// uint32Builder is the builder for uint32 field. +type uint32Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *uint32Builder) Unique() *uint32Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *uint32Builder) Range(i, j uint32) *uint32Builder { + b.validators = append(b.validators, func(v uint32) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *uint32Builder) Min(i uint32) *uint32Builder { + b.validators = append(b.validators, func(v uint32) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *uint32Builder) Max(i uint32) *uint32Builder { + b.validators = append(b.validators, func(v uint32) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *uint32Builder) Positive() *uint32Builder { + return b.Min(1) +} + +// Default sets the default value of the field. +func (b *uint32Builder) Default(i uint32) *uint32Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *uint32Builder) Nillable() *uint32Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *uint32Builder) Comment(c string) *uint32Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *uint32Builder) Optional() *uint32Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *uint32Builder) Immutable() *uint32Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *uint32Builder) StructTag(s string) *uint32Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *uint32Builder) Validate(fn func(uint32) error) *uint32Builder { + b.validators = append(b.validators, fn) + return b +} + +// uint64Builder is the builder for uint64 field. +type uint64Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *uint64Builder) Unique() *uint64Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *uint64Builder) Range(i, j uint64) *uint64Builder { + b.validators = append(b.validators, func(v uint64) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *uint64Builder) Min(i uint64) *uint64Builder { + b.validators = append(b.validators, func(v uint64) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *uint64Builder) Max(i uint64) *uint64Builder { + b.validators = append(b.validators, func(v uint64) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 1. Operation fails if the validator fails. +func (b *uint64Builder) Positive() *uint64Builder { + return b.Min(1) +} + +// Default sets the default value of the field. +func (b *uint64Builder) Default(i uint64) *uint64Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *uint64Builder) Nillable() *uint64Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *uint64Builder) Comment(c string) *uint64Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *uint64Builder) Optional() *uint64Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *uint64Builder) Immutable() *uint64Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *uint64Builder) StructTag(s string) *uint64Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *uint64Builder) Validate(fn func(uint64) error) *uint64Builder { + b.validators = append(b.validators, fn) + return b +} + +// float64Builder is the builder for float fields. +type float64Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *float64Builder) Unique() *float64Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *float64Builder) Range(i, j float64) *float64Builder { + b.validators = append(b.validators, func(v float64) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *float64Builder) Min(i float64) *float64Builder { + b.validators = append(b.validators, func(v float64) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *float64Builder) Max(i float64) *float64Builder { + b.validators = append(b.validators, func(v float64) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 0.000001. Operation fails if the validator fails. +func (b *float64Builder) Positive() *float64Builder { + return b.Min(1e-06) +} + +// Negative adds a maximum value validator with the value of -0.000001. Operation fails if the validator fails. +func (b *float64Builder) Negative() *float64Builder { + return b.Max(-1e-06) +} + +// Default sets the default value of the field. +func (b *float64Builder) Default(i float64) *float64Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *float64Builder) Nillable() *float64Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *float64Builder) Comment(c string) *float64Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *float64Builder) Optional() *float64Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *float64Builder) Immutable() *float64Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *float64Builder) StructTag(s string) *float64Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *float64Builder) Validate(fn func(float64) error) *float64Builder { + b.validators = append(b.validators, fn) + return b +} + +// float32Builder is the builder for float fields. +type float32Builder struct { + Field +} + +// Unique makes the field unique within all vertices of this type. +func (b *float32Builder) Unique() *float32Builder { + b.unique = true + return b +} + +// Range adds a range validator for this field where the given value needs to be in the range of [i, j]. +func (b *float32Builder) Range(i, j float32) *float32Builder { + b.validators = append(b.validators, func(v float32) error { + if v < i || v > j { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Min adds a minimum value validator for this field. Operation fails if the validator fails. +func (b *float32Builder) Min(i float32) *float32Builder { + b.validators = append(b.validators, func(v float32) error { + if v < i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Max adds a maximum value validator for this field. Operation fails if the validator fails. +func (b *float32Builder) Max(i float32) *float32Builder { + b.validators = append(b.validators, func(v float32) error { + if v > i { + return errors.New("value out of range") + } + return nil + }) + return b +} + +// Positive adds a minimum value validator with the value of 0.000001. Operation fails if the validator fails. +func (b *float32Builder) Positive() *float32Builder { + return b.Min(1e-06) +} + +// Negative adds a maximum value validator with the value of -0.000001. Operation fails if the validator fails. +func (b *float32Builder) Negative() *float32Builder { + return b.Max(-1e-06) +} + +// Default sets the default value of the field. +func (b *float32Builder) Default(i float32) *float32Builder { + b.value = i + return b +} + +// Nillable indicates that this field is a nillable. +// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field. +func (b *float32Builder) Nillable() *float32Builder { + b.nillable = true + return b +} + +// Comment sets the comment of the field. +func (b *float32Builder) Comment(c string) *float32Builder { + return b +} + +// Optional indicates that this field is optional on create. +// Unlike edges, fields are required by default. +func (b *float32Builder) Optional() *float32Builder { + b.optional = true + return b +} + +// Immutable indicates that this field cannot be updated. +func (b *float32Builder) Immutable() *float32Builder { + b.immutable = true + return b +} + +// StructTag sets the struct tag of the field. +func (b *float32Builder) StructTag(s string) *float32Builder { + b.tag = s + return b +} + +// Validate adds a validator for this field. Operation fails if the validation fails. +func (b *float32Builder) Validate(fn func(float32) error) *float32Builder { + b.validators = append(b.validators, fn) + return b +}