diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index bc84b494e..3a41fc619 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -579,7 +579,7 @@ func templateDialectSqlCreateTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlDecodeTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x55\xc1\x6e\xe3\x36\x10\x3d\x4b\x5f\x31\x35\x9c\x40\x32\xbc\x54\xba\xb7\x66\xe1\x02\x8b\x38\x01\x54\x14\x6e\xb1\x4e\x7b\xed\x32\xd4\x30\x66\x97\x26\x15\x92\xf2\x36\x50\xf5\xef\x05\x29\x31\x91\x1d\xb7\x36\x7a\xd8\x9b\xc4\x19\x3e\xbe\xf7\x66\xc8\x69\xdb\x62\x96\xde\xe8\xfa\xd9\x88\xc7\x8d\x83\xf7\x57\xdf\xff\xf0\xae\x36\x68\x51\x39\xb8\xa3\x0c\x1f\xb4\xfe\x02\xa5\x62\x04\x3e\x4a\x09\x21\xc9\x82\x8f\x9b\x1d\x56\x24\xbd\xdf\x08\x0b\x56\x37\x86\x21\x30\x5d\x21\x08\x0b\x52\x30\x54\x16\x2b\x68\x54\x85\x06\xdc\x06\xe1\x63\x4d\xd9\x06\xe1\x3d\xb9\x8a\x51\xe0\xba\x51\x55\x2a\x54\x88\xff\x5c\xde\xdc\xae\xd6\xb7\xc0\x85\x44\x18\xd6\x8c\xd6\x0e\x2a\x61\x90\x39\x6d\x9e\x41\x73\x70\xa3\xc3\x9c\x41\x24\xe9\xac\xe8\xba\x34\x6d\x5b\xa8\x90\x0b\x85\x30\xa9\x04\x95\xc8\x5c\x61\x9f\x64\x51\xa1\x67\x54\x68\x85\x13\xe8\x3a\x9f\x35\x35\xc8\x50\xec\xd0\xc0\xf5\x02\xa6\xe4\x53\xfc\xf3\x20\x45\x01\x77\x46\x6f\x3f\xe9\xaf\x16\x2c\xa3\xca\x06\x12\xf6\x49\x7a\xb5\xb5\xf6\x94\x2b\xea\x28\x08\xe5\x34\x78\x2c\xb2\xa2\x5b\x84\xae\x23\x29\x6f\x14\x83\x6c\x0f\xbf\xeb\x60\x36\x4e\xca\x5f\xc0\x33\xe3\x4f\x98\xd9\x27\x49\xfc\x6f\x0e\x68\x8c\x36\xd0\xa6\x49\xdb\xbe\x83\xa9\x3f\xda\xb3\xab\x8d\x50\x0e\x26\xbb\xc9\x1e\x68\x9a\xec\xa8\x09\xa7\x87\xbc\xae\x03\xeb\x4c\xc3\x9c\xdf\x9e\x94\x4b\x00\x1f\x13\x1c\xa6\xa4\x5c\x92\xd2\xae\x9d\x11\xea\x11\xba\x4e\x28\xd7\xb6\x80\xd2\x7a\x2e\x81\x57\xb9\x24\xf7\xcf\xf5\xf0\x8b\xaa\x0a\xe0\x49\xdb\x82\xa1\xea\x11\x61\xfa\xc7\x1c\xa6\xbc\xb7\xe9\x4e\xa0\xac\x6c\x9f\x10\x48\xd6\xd4\x32\x2a\x61\xca\xa3\xba\xc0\x88\x93\x55\x23\xe5\x00\xda\x63\x45\xdc\x2e\x4d\x8a\x22\xf8\xa9\x8d\x6f\x89\x0d\x1a\x04\xbb\xd1\x8d\xac\xe0\x01\x7b\xa3\x3d\x12\xb5\xb1\xf8\x9f\x03\xc9\x5f\x29\xfb\x42\x1f\x83\xc9\x37\x5a\x36\x5b\x65\x3f\x93\x34\x11\xdc\x7b\xe6\xb9\x79\x2b\xc9\x9a\x51\x95\x79\x6a\x97\x23\x5f\x48\xb9\x9c\x47\xba\x27\x14\xed\xef\x3b\xaa\xef\x05\x2a\x0a\xca\x3f\x04\x0a\xdf\x2d\x40\x09\x19\xcc\x37\xe8\x1a\xa3\xfc\x6a\x90\x7b\xd0\x0c\xa4\x5c\xc2\xe2\x5f\x6a\x63\x9d\x61\x5a\xed\x48\xe9\x34\xcd\xf6\x25\xe4\xfb\x45\x7b\x0d\x8c\xbc\x3d\xad\xd0\x67\xf8\x73\x39\x29\xed\x4f\xeb\x5f\x56\x83\x6e\xc1\x61\x47\x65\x83\x7e\xc3\xbe\x03\x6f\x0d\xf8\x00\x12\x55\x16\xd2\x73\xf8\x11\xae\x82\xe4\x64\x54\x89\x3f\xad\x56\xe4\x37\xb5\xa5\xc6\x6e\xa8\xec\x33\xe7\x70\x79\x68\xc3\x31\xec\xb7\x5e\x26\x2f\x76\xf2\xad\x23\xb7\xfe\x7e\xf0\x6c\xd2\x44\x74\xe0\x5e\x5c\xec\xb9\x1e\xe4\x1a\x2e\x76\x93\xb9\x07\xca\x03\x40\x50\x18\xc5\x07\x0b\x7b\x07\x56\x42\x4a\xfa\x20\x71\xd4\xcd\xd1\x9a\x7b\xb1\x8d\xcb\x6f\xca\x77\x8c\x37\x2c\xe0\xf2\x94\x6f\x2f\x7d\xd3\x17\x31\x9a\x76\xb2\xe1\xc8\xef\x54\x8a\x2a\x9a\x71\x26\x1b\x85\x5f\xb3\xde\x94\xe1\x12\xf6\x56\x24\xb3\x33\xf7\xfb\x65\xff\xea\x70\x98\x5c\x58\x72\x61\x27\x03\xc9\x6c\x3f\x39\x87\xbf\xc7\x97\x3d\x74\x5a\xd4\xd6\x1d\x5e\x94\x43\xf5\xdf\x8a\xca\x98\xc3\xf8\x7b\xe8\x2b\x25\x64\x1a\x26\xc2\xb0\x7e\x62\x84\x6c\xa9\x7a\x3e\x63\x86\x84\xb2\xfa\xf9\xd6\x87\xd6\x4c\xd7\x48\xd6\x61\xe1\x7f\x4d\x18\x3b\x6c\xfd\xcf\x09\x13\x93\xce\x99\x30\x5c\x9b\xfe\xcd\x5c\xe1\x5f\x2e\xcb\x43\x7f\x9d\x35\x75\x92\xf1\xc8\xb9\x1e\x1a\x3f\xd6\xab\xf5\x09\xaf\x4f\xc1\xb8\xb9\xf7\x28\x1d\xb9\xe8\xe3\x57\x33\x34\xcf\x61\xaf\xc2\x02\x68\x5d\xa3\xaa\xb2\xc3\xc8\x7c\x7c\x50\x1e\x1e\xdd\xe3\xc5\xfd\x27\x00\x00\xff\xff\xd4\xf5\x6a\x9c\xe2\x08\x00\x00") +var _templateDialectSqlDecodeTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x55\x5d\x6f\xdb\x36\x14\x7d\x96\x7e\xc5\x9d\xe0\x14\x92\xe1\x52\x59\xdf\x96\xc2\x03\x8a\x38\x01\x34\x0c\xde\x50\x77\x7b\x5d\x19\xea\xd2\xe6\x4a\x93\x0a\x49\xb9\x33\x34\xfd\xf7\x81\x94\x94\x48\x6e\x32\x1b\x7b\xd8\x9b\x45\x5e\x9e\x7b\xce\xb9\x1f\x6e\x9a\x7c\x1e\xdf\xea\xea\x68\xc4\x76\xe7\xe0\xdd\xf5\xf7\x3f\xbc\xad\x0c\x5a\x54\x0e\xee\x29\xc3\x07\xad\xbf\x40\xa1\x18\x81\x0f\x52\x42\x08\xb2\xe0\xef\xcd\x01\x4b\x12\x7f\xda\x09\x0b\x56\xd7\x86\x21\x30\x5d\x22\x08\x0b\x52\x30\x54\x16\x4b\xa8\x55\x89\x06\xdc\x0e\xe1\x43\x45\xd9\x0e\xe1\x1d\xb9\x1e\x6e\x81\xeb\x5a\x95\xb1\x50\xe1\xfe\xe7\xe2\xf6\x6e\xbd\xb9\x03\x2e\x24\x42\x7f\x66\xb4\x76\x50\x0a\x83\xcc\x69\x73\x04\xcd\xc1\x8d\x92\x39\x83\x48\xe2\x79\xde\xb6\x71\xdc\x34\x50\x22\x17\x0a\x21\x29\x05\x95\xc8\x5c\x6e\x1f\x65\x5e\xa2\x67\x94\x6b\x85\x09\xb4\xad\x8f\x9a\x19\x64\x28\x0e\x68\xe0\x66\x09\x33\xf2\x71\xf8\xf2\x20\x79\x0e\xf7\x46\xef\x3f\xea\xaf\x16\x2c\xa3\xca\x06\x12\xf6\x51\x7a\xb5\x95\xf6\x94\x4b\xea\x28\x08\xe5\x34\x78\x2c\xb2\xa6\x7b\x84\xb6\x25\x31\xaf\x15\x83\x74\x82\xdf\xb6\x30\x1f\x07\x65\x4f\xe0\xa9\xf1\x19\xe6\xf6\x51\x12\xff\x99\x01\x1a\xa3\x0d\x34\x71\xd4\x34\x6f\x61\xe6\x53\x7b\x76\x95\x11\xca\x41\x72\x48\x26\xa0\x71\x74\xa0\x26\x64\x0f\x71\x6d\x0b\xd6\x99\x9a\x39\xff\x3c\x2a\x56\x00\xfe\x4e\x70\x98\x91\x62\x45\x0a\xbb\x71\x46\xa8\x2d\xb4\xad\x50\xae\x69\x00\xa5\xf5\x5c\x02\xaf\x62\x45\x3e\x1d\xab\xfe\x13\x55\x19\xc0\xa3\xa6\x01\x43\xd5\x16\x61\xf6\xc7\x02\x66\xbc\xb3\xe9\x5e\xa0\x2c\x6d\x17\x10\x48\x56\xd4\x32\x2a\x61\xc6\x07\x75\x81\x11\x27\xeb\x5a\xca\x1e\xb4\xc3\x1a\x70\xdb\x38\xca\xf3\xe0\xa7\x36\xbe\x25\x76\x68\x10\xec\x4e\xd7\xb2\x84\x07\xec\x8c\xf6\x48\xd4\x0e\xc5\xff\x1c\x48\xfe\x4a\xd9\x17\xba\x0d\x26\xdf\x6a\x59\xef\x95\xfd\x4c\xe2\x48\x70\xef\x99\xe7\xe6\xad\x24\x1b\x46\x55\xea\xa9\xbd\x19\xf9\x42\x8a\xd5\x62\xa0\x7b\x46\xd1\xf4\xdd\x8b\xfa\x9e\xa0\x06\x41\xd9\xfb\x40\xe1\xbb\x25\x28\x21\x83\xf9\x06\x5d\x6d\x94\x3f\x0d\x72\x4f\x9a\x81\x14\x2b\x58\xbe\x52\x1b\xeb\x0c\xd3\xea\x40\x0a\xa7\x69\x3a\x95\x90\x4d\x8b\xf6\x7c\x31\xf2\xf6\xbc\x42\x1f\xe1\xf3\x72\x52\xd8\x9f\x36\xbf\xac\x7b\xdd\x82\xc3\x81\xca\x1a\xfd\x83\xa9\x03\xdf\x1a\xf0\x1e\x24\xaa\x34\x84\x67\xf0\x23\x5c\x07\xc9\xd1\xa8\x12\x7f\x5a\xad\xc8\x6f\x6a\x4f\x8d\xdd\x51\xd9\x45\x2e\xe0\xcd\xa9\x0d\x2f\x61\x7f\xeb\x65\xf4\x64\x27\xdf\x3b\x72\xe7\xe7\x83\xa7\x49\x3d\xa0\x03\xf7\xe2\x86\x9e\xeb\x40\x6e\xe0\xea\x90\x2c\x3c\x50\x16\x00\x82\xc2\x41\x7c\xb0\xb0\x73\x60\x2d\xa4\xa4\x0f\x12\x9f\x3d\x38\x5b\x7c\xf2\x3b\x95\xa2\xec\x89\x5d\x22\x08\x96\xa0\xf0\x6b\xda\xf1\xeb\xe7\xa1\x63\x35\xbf\xf0\xb9\x3f\xf6\xf3\xcf\x21\xb9\xb2\xe4\xca\x26\x3d\xc5\x74\x1a\x9c\xc1\xdf\xe3\xb1\x0b\x35\xef\x85\x4d\xa4\x0f\x93\xfb\xff\xe4\x1e\xcf\xc9\xf8\x77\x5f\x52\x25\x64\x1c\x96\x71\x7f\x7e\x66\x7b\xef\xa9\x3a\x5e\xb0\xbe\x43\x15\xfd\x5f\x4b\x77\xb5\x61\xba\x42\xb2\x09\x07\xff\x69\xb9\xdb\xfe\xe9\xbf\x2e\xf7\x21\xe8\x92\xe5\xce\xb5\xe9\xd6\xd5\x1a\xff\x72\x69\x16\xda\xe9\xa2\x85\x1f\x8d\xb7\xfd\xcd\xb2\x9b\xa9\xa1\x5e\x8d\x0f\x78\x9e\xc2\x71\x2f\x4f\x28\xbd\x30\x63\xe3\x85\x15\xda\xe5\xb4\x39\x61\x09\xb4\xaa\x50\x95\xe9\xe9\xcd\x62\x9c\x28\x0b\xfb\xee\x95\xe2\xfe\x13\x00\x00\xff\xff\x46\x9c\x88\x2c\x5e\x08\x00\x00") func templateDialectSqlDecodeTmplBytes() ([]byte, error) { return bindataRead( @@ -594,7 +594,7 @@ func templateDialectSqlDecodeTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/decode.tmpl", size: 2274, mode: os.FileMode(420), modTime: time.Unix(1568800068, 0)} + info := bindataFileInfo{name: "template/dialect/sql/decode.tmpl", size: 2142, mode: os.FileMode(420), modTime: time.Unix(1570172976, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/dialect/sql/decode.tmpl b/entc/gen/template/dialect/sql/decode.tmpl index 1aa1d9c3a..cfe85166c 100644 --- a/entc/gen/template/dialect/sql/decode.tmpl +++ b/entc/gen/template/dialect/sql/decode.tmpl @@ -34,14 +34,10 @@ func ({{ $receiver }} *{{ $.Name }}) FromRows(rows *sql.Rows) error { } } {{- else if $f.Nillable }} - {{- if $f.IsTime }} - {{ $receiver }}.{{ pascal $f.Name }} = &{{ $scan }}.{{ pascal $f.Name }} - {{- else }} - if {{ $scan }}.{{- pascal $f.Name }}.Valid { - {{ $receiver }}.{{ pascal $f.Name }} = new({{ $f.Type }}) - *{{ $receiver }}.{{ pascal $f.Name }} = {{ printf "%s.%s" $scan (pascal $f.Name) | $f.NullTypeField }} - } - {{- end }} + if {{ $scan }}.{{- pascal $f.Name }}.Valid { + {{ $receiver }}.{{ pascal $f.Name }} = new({{ $f.Type }}) + *{{ $receiver }}.{{ pascal $f.Name }} = {{ printf "%s.%s" $scan (pascal $f.Name) | $f.NullTypeField }} + } {{- else }} {{ $receiver }}.{{ pascal $f.Name }} = {{ printf "%s.%s" $scan (pascal $f.Name) | $f.NullTypeField }} {{- end }} @@ -66,4 +62,4 @@ func ({{ $receiver }} *{{ $slice }}) FromRows(rows *sql.Rows) error { } return nil } -{{ end }} \ No newline at end of file +{{ end }} diff --git a/entc/integration/template/ent/example_test.go b/entc/integration/template/ent/example_test.go index 84c2c26ab..22941fe65 100644 --- a/entc/integration/template/ent/example_test.go +++ b/entc/integration/template/ent/example_test.go @@ -9,6 +9,7 @@ package ent import ( "context" "log" + "time" "github.com/facebookincubator/ent/dialect/sql" ) @@ -60,6 +61,7 @@ func ExamplePet() { pe := client.Pet. Create(). SetAge(1). + SetLicensedAt(time.Now()). SaveX(ctx) log.Println("pet created:", pe) @@ -82,6 +84,7 @@ func ExampleUser() { pe0 := client.Pet. Create(). SetAge(1). + SetLicensedAt(time.Now()). SaveX(ctx) log.Println("pet created:", pe0) u1 := client.User. diff --git a/entc/integration/template/ent/migrate/schema.go b/entc/integration/template/ent/migrate/schema.go index b0dd0bd97..0296218ce 100644 --- a/entc/integration/template/ent/migrate/schema.go +++ b/entc/integration/template/ent/migrate/schema.go @@ -28,6 +28,7 @@ var ( PetsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "age", Type: field.TypeInt}, + {Name: "licensed_at", Type: field.TypeTime, Nullable: true}, {Name: "owner_id", Type: field.TypeInt, Nullable: true}, } // PetsTable holds the schema information for the "pets" table. @@ -38,7 +39,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "pets_users_pets", - Columns: []*schema.Column{PetsColumns[2]}, + Columns: []*schema.Column{PetsColumns[3]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, diff --git a/entc/integration/template/ent/node.go b/entc/integration/template/ent/node.go index ae512aba5..ed9fe720d 100644 --- a/entc/integration/template/ent/node.go +++ b/entc/integration/template/ent/node.go @@ -68,7 +68,7 @@ func (pe *Pet) Node(ctx context.Context) (node *Node, err error) { node = &Node{ ID: pe.ID, Type: "Pet", - Fields: make([]*Field, 1), + Fields: make([]*Field, 2), Edges: make([]*Edge, 1), } var buf []byte @@ -80,6 +80,14 @@ func (pe *Pet) Node(ctx context.Context) (node *Node, err error) { Name: "Age", Value: string(buf), } + if buf, err = json.Marshal(pe.LicensedAt); err != nil { + return nil, err + } + node.Fields[1] = &Field{ + Type: "time.Time", + Name: "LicensedAt", + Value: string(buf), + } var ids []int ids, err = pe.QueryOwner(). Select(user.FieldID). diff --git a/entc/integration/template/ent/pet.go b/entc/integration/template/ent/pet.go index ed93d1c38..de2704585 100644 --- a/entc/integration/template/ent/pet.go +++ b/entc/integration/template/ent/pet.go @@ -9,6 +9,7 @@ package ent import ( "bytes" "fmt" + "time" "github.com/facebookincubator/ent/dialect/sql" ) @@ -20,23 +21,31 @@ type Pet struct { ID int `json:"id,omitempty"` // Age holds the value of the "age" field. Age int `json:"age,omitempty"` + // LicensedAt holds the value of the "licensed_at" field. + LicensedAt *time.Time `json:"licensed_at,omitempty"` } // FromRows scans the sql response data into Pet. func (pe *Pet) FromRows(rows *sql.Rows) error { var vpe struct { - ID int - Age sql.NullInt64 + ID int + Age sql.NullInt64 + LicensedAt sql.NullTime } // the order here should be the same as in the `pet.Columns`. if err := rows.Scan( &vpe.ID, &vpe.Age, + &vpe.LicensedAt, ); err != nil { return err } pe.ID = vpe.ID pe.Age = int(vpe.Age.Int64) + if vpe.LicensedAt.Valid { + pe.LicensedAt = new(time.Time) + *pe.LicensedAt = vpe.LicensedAt.Time + } return nil } @@ -69,6 +78,9 @@ func (pe *Pet) String() string { buf.WriteString("Pet(") buf.WriteString(fmt.Sprintf("id=%v", pe.ID)) buf.WriteString(fmt.Sprintf(", age=%v", pe.Age)) + if v := pe.LicensedAt; v != nil { + buf.WriteString(fmt.Sprintf(", licensed_at=%v", *v)) + } buf.WriteString(")") return buf.String() } diff --git a/entc/integration/template/ent/pet/pet.go b/entc/integration/template/ent/pet/pet.go index f67600701..42cd1adf2 100644 --- a/entc/integration/template/ent/pet/pet.go +++ b/entc/integration/template/ent/pet/pet.go @@ -13,6 +13,8 @@ const ( FieldID = "id" // FieldAge holds the string denoting the age vertex property in the database. FieldAge = "age" + // FieldLicensedAt holds the string denoting the licensed_at vertex property in the database. + FieldLicensedAt = "licensed_at" // Table holds the table name of the pet in the database. Table = "pets" @@ -29,4 +31,5 @@ const ( var Columns = []string{ FieldID, FieldAge, + FieldLicensedAt, } diff --git a/entc/integration/template/ent/pet/where.go b/entc/integration/template/ent/pet/where.go index 077b9adb9..fda476fbf 100644 --- a/entc/integration/template/ent/pet/where.go +++ b/entc/integration/template/ent/pet/where.go @@ -7,6 +7,8 @@ package pet import ( + "time" + "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/template/ent/predicate" ) @@ -121,6 +123,15 @@ func Age(v int) predicate.Pet { ) } +// LicensedAt applies equality check predicate on the "licensed_at" field. It's identical to LicensedAtEQ. +func LicensedAt(v time.Time) predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldLicensedAt), v)) + }, + ) +} + // AgeEQ applies the EQ predicate on the "age" field. func AgeEQ(v int) predicate.Pet { return predicate.Pet( @@ -213,6 +224,116 @@ func AgeLTE(v int) predicate.Pet { ) } +// LicensedAtEQ applies the EQ predicate on the "licensed_at" field. +func LicensedAtEQ(v time.Time) predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldLicensedAt), v)) + }, + ) +} + +// LicensedAtNEQ applies the NEQ predicate on the "licensed_at" field. +func LicensedAtNEQ(v time.Time) predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldLicensedAt), v)) + }, + ) +} + +// LicensedAtIn applies the In predicate on the "licensed_at" field. +func LicensedAtIn(vs ...time.Time) predicate.Pet { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Pet( + 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(FieldLicensedAt), v...)) + }, + ) +} + +// LicensedAtNotIn applies the NotIn predicate on the "licensed_at" field. +func LicensedAtNotIn(vs ...time.Time) predicate.Pet { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Pet( + 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(FieldLicensedAt), v...)) + }, + ) +} + +// LicensedAtGT applies the GT predicate on the "licensed_at" field. +func LicensedAtGT(v time.Time) predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldLicensedAt), v)) + }, + ) +} + +// LicensedAtGTE applies the GTE predicate on the "licensed_at" field. +func LicensedAtGTE(v time.Time) predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldLicensedAt), v)) + }, + ) +} + +// LicensedAtLT applies the LT predicate on the "licensed_at" field. +func LicensedAtLT(v time.Time) predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldLicensedAt), v)) + }, + ) +} + +// LicensedAtLTE applies the LTE predicate on the "licensed_at" field. +func LicensedAtLTE(v time.Time) predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldLicensedAt), v)) + }, + ) +} + +// LicensedAtIsNil applies the IsNil predicate on the "licensed_at" field. +func LicensedAtIsNil() predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldLicensedAt))) + }, + ) +} + +// LicensedAtNotNil applies the NotNil predicate on the "licensed_at" field. +func LicensedAtNotNil() predicate.Pet { + return predicate.Pet( + func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldLicensedAt))) + }, + ) +} + // HasOwner applies the HasEdge predicate on the "owner" edge. func HasOwner() predicate.Pet { return predicate.Pet( diff --git a/entc/integration/template/ent/pet_create.go b/entc/integration/template/ent/pet_create.go index 3d0b0b07a..7a1fadabc 100644 --- a/entc/integration/template/ent/pet_create.go +++ b/entc/integration/template/ent/pet_create.go @@ -9,6 +9,7 @@ package ent import ( "context" "errors" + "time" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/template/ent/pet" @@ -17,8 +18,9 @@ import ( // PetCreate is the builder for creating a Pet entity. type PetCreate struct { config - age *int - owner map[int]struct{} + age *int + licensed_at *time.Time + owner map[int]struct{} } // SetAge sets the age field. @@ -27,6 +29,20 @@ func (pc *PetCreate) SetAge(i int) *PetCreate { return pc } +// SetLicensedAt sets the licensed_at field. +func (pc *PetCreate) SetLicensedAt(t time.Time) *PetCreate { + pc.licensed_at = &t + return pc +} + +// SetNillableLicensedAt sets the licensed_at field if the given value is not nil. +func (pc *PetCreate) SetNillableLicensedAt(t *time.Time) *PetCreate { + if t != nil { + pc.SetLicensedAt(*t) + } + return pc +} + // SetOwnerID sets the owner edge to User by id. func (pc *PetCreate) SetOwnerID(id int) *PetCreate { if pc.owner == nil { @@ -83,6 +99,10 @@ func (pc *PetCreate) sqlSave(ctx context.Context) (*Pet, error) { builder.Set(pet.FieldAge, *value) pe.Age = *value } + if value := pc.licensed_at; value != nil { + builder.Set(pet.FieldLicensedAt, *value) + pe.LicensedAt = value + } query, args := builder.Query() if err := tx.Exec(ctx, query, args, &res); err != nil { return nil, rollback(tx, err) diff --git a/entc/integration/template/ent/pet_update.go b/entc/integration/template/ent/pet_update.go index ccaef41fe..fb48fa95f 100644 --- a/entc/integration/template/ent/pet_update.go +++ b/entc/integration/template/ent/pet_update.go @@ -10,6 +10,7 @@ import ( "context" "errors" "fmt" + "time" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/template/ent/pet" @@ -20,11 +21,13 @@ import ( // PetUpdate is the builder for updating Pet entities. type PetUpdate struct { config - age *int - addage *int - owner map[int]struct{} - clearedOwner bool - predicates []predicate.Pet + age *int + addage *int + licensed_at *time.Time + clearlicensed_at bool + owner map[int]struct{} + clearedOwner bool + predicates []predicate.Pet } // Where adds a new predicate for the builder. @@ -50,6 +53,27 @@ func (pu *PetUpdate) AddAge(i int) *PetUpdate { return pu } +// SetLicensedAt sets the licensed_at field. +func (pu *PetUpdate) SetLicensedAt(t time.Time) *PetUpdate { + pu.licensed_at = &t + return pu +} + +// SetNillableLicensedAt sets the licensed_at field if the given value is not nil. +func (pu *PetUpdate) SetNillableLicensedAt(t *time.Time) *PetUpdate { + if t != nil { + pu.SetLicensedAt(*t) + } + return pu +} + +// ClearLicensedAt clears the value of licensed_at. +func (pu *PetUpdate) ClearLicensedAt() *PetUpdate { + pu.licensed_at = nil + pu.clearlicensed_at = true + return pu +} + // SetOwnerID sets the owner edge to User by id. func (pu *PetUpdate) SetOwnerID(id int) *PetUpdate { if pu.owner == nil { @@ -145,6 +169,12 @@ func (pu *PetUpdate) sqlSave(ctx context.Context) (n int, err error) { if value := pu.addage; value != nil { builder.Add(pet.FieldAge, *value) } + if value := pu.licensed_at; value != nil { + builder.Set(pet.FieldLicensedAt, *value) + } + if pu.clearlicensed_at { + builder.SetNull(pet.FieldLicensedAt) + } if !builder.Empty() { query, args := builder.Query() if err := tx.Exec(ctx, query, args, &res); err != nil { @@ -180,11 +210,13 @@ func (pu *PetUpdate) sqlSave(ctx context.Context) (n int, err error) { // PetUpdateOne is the builder for updating a single Pet entity. type PetUpdateOne struct { config - id int - age *int - addage *int - owner map[int]struct{} - clearedOwner bool + id int + age *int + addage *int + licensed_at *time.Time + clearlicensed_at bool + owner map[int]struct{} + clearedOwner bool } // SetAge sets the age field. @@ -204,6 +236,27 @@ func (puo *PetUpdateOne) AddAge(i int) *PetUpdateOne { return puo } +// SetLicensedAt sets the licensed_at field. +func (puo *PetUpdateOne) SetLicensedAt(t time.Time) *PetUpdateOne { + puo.licensed_at = &t + return puo +} + +// SetNillableLicensedAt sets the licensed_at field if the given value is not nil. +func (puo *PetUpdateOne) SetNillableLicensedAt(t *time.Time) *PetUpdateOne { + if t != nil { + puo.SetLicensedAt(*t) + } + return puo +} + +// ClearLicensedAt clears the value of licensed_at. +func (puo *PetUpdateOne) ClearLicensedAt() *PetUpdateOne { + puo.licensed_at = nil + puo.clearlicensed_at = true + return puo +} + // SetOwnerID sets the owner edge to User by id. func (puo *PetUpdateOne) SetOwnerID(id int) *PetUpdateOne { if puo.owner == nil { @@ -304,6 +357,14 @@ func (puo *PetUpdateOne) sqlSave(ctx context.Context) (pe *Pet, err error) { builder.Add(pet.FieldAge, *value) pe.Age += *value } + if value := puo.licensed_at; value != nil { + builder.Set(pet.FieldLicensedAt, *value) + pe.LicensedAt = value + } + if puo.clearlicensed_at { + pe.LicensedAt = nil + builder.SetNull(pet.FieldLicensedAt) + } if !builder.Empty() { query, args := builder.Query() if err := tx.Exec(ctx, query, args, &res); err != nil { diff --git a/entc/integration/template/ent/schema/pet.go b/entc/integration/template/ent/schema/pet.go index e29ca4ed5..22d5d6fc2 100644 --- a/entc/integration/template/ent/schema/pet.go +++ b/entc/integration/template/ent/schema/pet.go @@ -19,6 +19,7 @@ type Pet struct { func (Pet) Fields() []ent.Field { return []ent.Field{ field.Int("age"), + field.Time("licensed_at").Optional().Nillable(), } }