From 2cc8286f5f2aa8c78a308bfa35ccce042b4c7e96 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Sun, 4 Aug 2019 03:08:47 -0700 Subject: [PATCH] entc: add idtype option codegen Reviewed By: alexsn Differential Revision: D16601757 fbshipit-source-id: 35d5fbfb4ef40bae192e084ad4e067880175e71c --- entc/cmd/entc/entc.go | 31 +++++++++++++ entc/gen/bindata.go | 10 ++--- entc/gen/graph.go | 3 ++ entc/gen/template/dialect/sql/create.tmpl | 2 +- entc/gen/template/dialect/sql/predicate.tmpl | 4 +- entc/gen/type.go | 2 +- entc/integration/ent/card/where.go | 24 +++++------ entc/integration/ent/comment/where.go | 24 +++++------ entc/integration/ent/fieldtype/where.go | 24 +++++------ entc/integration/ent/file/where.go | 24 +++++------ entc/integration/ent/group/where.go | 24 +++++------ entc/integration/ent/groupinfo/where.go | 24 +++++------ entc/integration/ent/node/where.go | 24 +++++------ entc/integration/ent/pet/where.go | 24 +++++------ entc/integration/ent/user/where.go | 24 +++++------ entc/integration/generate.go | 2 +- entc/integration/migrate/entv1/client.go | 4 +- entc/integration/migrate/entv1/ent.go | 4 +- entc/integration/migrate/entv1/user.go | 11 +---- entc/integration/migrate/entv1/user/where.go | 43 ++++++++----------- entc/integration/migrate/entv1/user_create.go | 3 +- entc/integration/migrate/entv1/user_query.go | 24 +++++------ entc/integration/migrate/entv1/user_update.go | 4 +- entc/integration/migrate/entv2/client.go | 12 +++--- entc/integration/migrate/entv2/ent.go | 4 +- entc/integration/migrate/entv2/group.go | 11 +---- entc/integration/migrate/entv2/group/where.go | 43 ++++++++----------- .../integration/migrate/entv2/group_create.go | 3 +- entc/integration/migrate/entv2/group_query.go | 24 +++++------ .../integration/migrate/entv2/group_update.go | 4 +- entc/integration/migrate/entv2/pet.go | 11 +---- entc/integration/migrate/entv2/pet/where.go | 43 ++++++++----------- entc/integration/migrate/entv2/pet_create.go | 3 +- entc/integration/migrate/entv2/pet_query.go | 24 +++++------ entc/integration/migrate/entv2/pet_update.go | 4 +- entc/integration/migrate/entv2/user.go | 11 +---- entc/integration/migrate/entv2/user/where.go | 43 ++++++++----------- entc/integration/migrate/entv2/user_create.go | 3 +- entc/integration/migrate/entv2/user_query.go | 24 +++++------ entc/integration/migrate/entv2/user_update.go | 4 +- entc/integration/migrate/migrate_test.go | 7 +-- 41 files changed, 302 insertions(+), 339 deletions(-) diff --git a/entc/cmd/entc/entc.go b/entc/cmd/entc/entc.go index fad830eea..cb1ca1542 100644 --- a/entc/cmd/entc/entc.go +++ b/entc/cmd/entc/entc.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "fmt" "io/ioutil" "os" @@ -12,6 +13,7 @@ import ( "fbc/ent/entc/gen" "fbc/ent/entc/load" + "fbc/ent/field" "github.com/spf13/cobra" ) @@ -68,6 +70,7 @@ func main() { var ( cfg gen.Config storage []string + idtype = idType(field.TypeInt) cmd = &cobra.Command{ Use: "generate [flags] path", Short: "generate go code for the schema directory", @@ -87,12 +90,14 @@ func main() { failOnErr(err) cfg.Storage = append(cfg.Storage, sr) } + cfg.IDType = field.Type(idtype) graph, err := loadGraph(path[0], cfg) failOnErr(err) failOnErr(graph.Gen()) }, } ) + cmd.Flags().Var(&idtype, "idtype", "type of the id field") cmd.Flags().StringVar(&cfg.Header, "header", "", "override codegen header") cmd.Flags().StringVar(&cfg.Target, "target", "", "target directory for codegen") cmd.Flags().StringSliceVarP(&storage, "storage", "", []string{"sql"}, "list of storage drivers to support") @@ -139,6 +144,32 @@ func ({{ . }}) Edges() []ent.Edge { } `)) +// custom implementation for pflag. +type idType field.Type + +// Set implements the Set method of the flag.Value interface. +func (t *idType) Set(s string) error { + switch s { + case field.TypeInt.String(): + *t = idType(field.TypeInt) + case field.TypeString.String(): + *t = idType(field.TypeString) + default: + return errors.New("invalid type") + } + return nil +} + +// Type returns the type representation of the id option for help command. +func (idType) Type() string { + return fmt.Sprintf("[%s %s]", field.TypeInt, field.TypeString) +} + +// String returns the default value for the help command. +func (idType) String() string { + return field.TypeInt.String() +} + func failOnErr(err error) { if err != nil { fmt.Fprint(os.Stderr, err.Error()) diff --git a/entc/gen/bindata.go b/entc/gen/bindata.go index c1ff1d586..0927265ba 100644 --- a/entc/gen/bindata.go +++ b/entc/gen/bindata.go @@ -199,7 +199,7 @@ func templateBuilderSetterTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/setter.tmpl", size: 3040, mode: os.FileMode(420), modTime: time.Unix(1564666719, 0)} + info := bindataFileInfo{name: "template/builder/setter.tmpl", size: 3040, mode: os.FileMode(420), modTime: time.Unix(1564668403, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -504,7 +504,7 @@ func templateDialectSqlByTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlCreateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\x5d\x6f\xdb\x36\x14\x7d\x96\x7e\xc5\x9d\xe1\x16\x52\xe0\x30\x69\x1f\xb3\x65\x40\xd7\xa4\x80\xb1\x75\x69\xe3\x74\x7b\x68\x8b\x81\x96\x2e\x1d\x22\x32\xe5\x90\xb4\xe3\xc0\xd0\x7f\x1f\x2e\x65\x59\xb2\x2c\x7f\xc4\x0d\xea\x6d\x98\x5e\x12\xc9\xf7\x8b\xe7\x1e\xde\x43\x69\x36\x83\x18\x85\x54\x08\xad\x58\xf2\x04\x23\x7b\x62\xee\x93\x93\x48\x23\xb7\xd8\x82\x2c\xf3\x67\x33\x68\xf7\xc7\x32\x89\x51\xc3\xd9\x39\x8c\xb8\x89\x78\x02\x6d\xd6\x8b\xd2\x11\xb2\x5f\xe6\xbf\xcc\x0d\x35\x46\x28\x27\xb9\xe5\xe2\xff\x85\x7b\x96\xf9\xbe\x18\xab\x08\x82\x25\xdb\x2c\x83\xa3\x6a\x96\x2c\x0b\xc1\xdc\x27\x3d\x3e\xc1\x20\xb2\x53\x88\x52\x65\x71\x6a\xd9\xdb\xfc\x6f\x08\x81\x33\x67\xbf\xf3\x21\x42\x96\x75\x00\xb5\x4e\x75\x08\x33\xdf\x9b\x70\x0d\x81\xef\x79\x1a\x0d\x85\x60\xd7\x68\xc6\x89\xf5\x3d\xcf\x39\x5c\x57\x32\x9e\xc3\xcb\x6a\x90\x59\x94\x2a\x21\x07\x67\x50\xab\x8c\xe5\xcf\x33\xdf\x0b\x7d\xcf\x4e\x5d\x2e\x5a\x5c\xdd\x2c\xd6\xf4\x1f\xbb\x99\x52\xc5\xa1\xef\x49\xe1\x2c\x7f\x38\x07\x25\x13\xaa\xcc\xd3\x68\xc7\x5a\xd1\xad\x0b\xe2\x7b\x99\xef\x55\x70\xa5\x6a\xbb\xca\xa0\xb6\x0e\x1c\xf6\x81\x47\x77\x7c\x40\xa5\xb1\x1b\xde\x4f\x30\x64\x17\x28\xf8\x38\xb1\x75\xec\x8a\xd4\x17\x79\xfb\x82\x30\xf4\xbd\xd9\xec\x18\x34\x57\x03\x84\xf6\x5f\x1d\x68\x0b\x4a\xd0\x66\xef\x24\x26\xb1\xa1\x2e\x78\x54\x5f\x3d\x0e\x39\xb5\x05\xeb\x59\x3d\x8e\xac\xb3\x25\x9c\x2a\x2b\x28\xca\x65\x3d\x5c\x2d\x92\xee\x05\xb5\xc8\x58\xae\xac\x6b\xcb\xd1\x6a\x86\xd5\x04\x21\x05\xae\x77\x87\x2c\x0b\xa2\x89\xa2\x45\xe0\x50\x97\x02\x54\x6a\xdd\xe3\x71\x92\x10\x32\x90\x65\x94\x09\x15\x85\xdb\x25\xa5\xef\x11\xf6\xb4\xdc\xdc\xc7\xf7\xee\xc7\xa8\x1f\x3b\xc0\xf5\xc0\x10\x54\xc5\x3a\x3f\xd2\xe3\xa0\xec\xe6\xd9\x39\xd8\x29\xbb\x9c\x62\x44\x5d\xee\x40\xc5\xad\x03\x2f\x35\x9a\xf0\xc7\x4d\x5d\xd7\x69\x92\xf4\x79\x74\x17\xcc\x79\x14\x3a\x0e\xc8\x78\x41\x2a\x8d\x86\xfd\xc6\x8d\xcd\x79\xd0\x8d\x83\xad\x44\x6a\x0e\xb9\x02\x67\xf7\x62\x01\x5e\x9b\x75\x2f\x58\xd7\xf4\xac\x96\x6a\x00\x59\x66\xac\x8e\x52\x35\x61\xef\x52\x3d\xe4\xb6\xab\x6c\x40\x05\xbd\x3a\x0d\x09\xd2\xc4\x10\xba\x32\x5e\xc0\xbb\x42\x2d\xcc\xa9\x75\x19\x0f\xb0\x64\x56\x82\x6a\x85\xa5\x74\x8f\xf5\xde\xc3\xcf\x70\x9a\x53\x8b\xc2\x4a\x01\x5c\xc5\x64\xf6\x49\xc9\xfb\x31\x3a\x07\x4c\xc4\x35\x0a\xd7\xd9\x93\x23\xb8\x7a\x7d\x05\x0f\xd2\xde\x82\xc1\x44\x80\x46\x81\x1a\x55\x84\x70\x74\xe2\x72\x7b\x9e\x48\x35\xa0\x8c\x1d\x9a\xae\xca\x5d\xea\xc8\x4b\xc8\x8b\xb0\x38\x1c\x25\xdc\x36\xce\xc3\x13\x42\x0a\xb5\x95\x71\x8b\x56\x7e\x3c\xcf\x59\xa7\x0f\x6d\xe5\x4f\xa3\x98\x5b\x6c\xdc\x25\x98\x6f\xe8\xca\x56\x09\x59\x1e\xc7\xf3\xd6\xed\x2c\x64\x6f\xd3\x64\x3c\x54\x4b\xfb\x0b\x65\x5c\x7a\xfe\x79\x8b\x1a\x03\x4a\x7d\xf9\xb1\x31\x04\xf5\x7d\xc9\x5d\xc6\x61\x58\x52\x9c\xae\xfd\x69\x4e\xd7\x16\x5e\xd2\xd5\x80\xd7\xf7\x83\x6b\x23\x5a\xc8\x6e\x1e\x47\xd8\x90\x9b\x9e\xd6\x91\x73\xc0\xbf\x51\x71\x10\xb2\xae\xa1\x31\xb4\x6b\x11\x87\x02\x9c\x0b\x81\x91\xc5\xe5\x49\x73\x9d\x3e\x98\x37\xf3\x1f\x6a\x05\xed\x9d\x48\x0a\x90\xca\x06\x45\xbe\x10\x7e\x7a\xc2\x30\xd8\x9a\xee\xe5\xa5\xd6\x0e\x4d\xcd\xa5\xb2\xef\xb8\x4c\x30\x9e\x0d\xcd\xe0\x0c\xc4\xd0\xb2\xde\x48\x4b\x65\x45\xd0\xfa\xd2\xca\xe3\xcf\x75\xe3\x4b\x0b\x82\x17\x93\x10\x78\xa2\x91\xc7\x8f\x74\x9c\x50\xae\x3a\xb0\x29\x70\x88\xa5\x70\x53\xc4\x42\xee\x57\xba\xb5\xf2\x4e\x67\x4b\x4b\xcc\x8a\x69\xe5\x86\x23\x0d\x54\x64\xef\x5f\xbf\x07\x38\xe4\x00\xa2\x98\x9c\x52\x9e\xce\x25\xb0\x4f\x37\xaf\xdc\xcd\xf1\xbc\xc8\xae\xe9\x92\xaf\x9b\xe8\xb9\x7d\x61\x41\xe6\x0b\xd7\x62\xce\xaf\x99\x6b\x6b\x8e\x28\xdb\x36\x6a\xbe\x13\xcc\x1a\xbf\x0f\xbf\x56\x9c\x3e\xe7\xc5\x65\xd9\xd7\x0e\xec\x6a\xde\x27\xf3\x32\xdb\x1f\x3c\x19\xa3\x71\x42\xb6\x34\x23\x4b\x30\x6a\xb2\x42\x6a\x72\xac\x51\x40\x0e\xb3\x01\x7b\x8b\x80\x4e\xd3\xa4\x82\x7e\x6a\x6f\xe1\x81\x3f\x1a\x56\xea\x4c\x25\x0d\x52\x9e\x7a\x9a\x2a\x8c\x9e\x77\x88\x4d\xdf\x4c\xd4\xab\x83\xf2\xf4\xd9\x84\x72\x6f\x9d\xdc\x53\x26\xfd\x7f\x56\x1f\xaf\x5e\xbf\x2f\xfa\x38\x2a\x80\xfc\x30\xaf\xeb\x20\x8d\x1d\xb1\x2b\x1d\x84\x7b\x8b\x69\xb9\xd0\x67\xa3\xc8\x9e\x47\x83\x92\x1f\xa4\xef\xa3\x4e\x3e\xf4\x9e\x28\xf2\x45\xb0\x2a\x5d\xbe\x89\x2d\xdb\xc9\x92\x83\xb7\xab\xce\x37\xca\xfc\xae\x49\x9e\x43\xe3\xbf\x55\xe2\x53\x85\x90\x0a\x58\x55\xfa\x17\x93\xbd\x74\xfe\x0e\x1f\xcd\x6e\x2b\x28\x8e\x03\xcb\xdb\xb2\xf2\x7a\xb2\x90\x88\x42\x6d\x16\xb4\xaf\xbc\x75\xe5\x28\x60\xe5\xdd\xaf\x78\x0f\x7b\x63\x53\x19\xec\x5e\xce\xe7\xd3\xaf\x3b\x1f\xdd\xdc\x57\x87\xb2\x8f\x95\xe2\x17\xe5\x50\x25\x4f\x4a\xee\x37\x08\x5e\xf3\x99\xe3\x5f\xad\x00\xfb\x9e\xf6\x1b\x74\x63\x05\xf6\xc3\x40\xb2\x09\x91\xef\xf6\x32\xb4\x0e\x9e\x92\x4b\xff\x8f\xcd\xff\xea\xd8\x54\xcd\x9f\xe2\x96\x1a\xfe\x36\x1d\x0e\xa5\x0d\x36\x7f\x56\x2b\x3e\xa6\xce\x9f\xd5\x3f\x7e\x75\xc8\xca\xcf\x7c\xbf\x7c\xb9\xf1\x37\x7e\xf5\xae\x9e\x71\x8a\x2f\x5e\x1b\xe6\xf8\xda\x21\x3e\x3f\xd8\x34\x90\x66\x1b\x65\x96\x21\x29\xeb\xfe\x3b\x00\x00\xff\xff\x43\x26\xae\xa1\xad\x17\x00\x00") +var _templateDialectSqlCreateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\x5d\x6f\xdb\x36\x14\x7d\x96\x7e\xc5\x9d\xe1\x16\x52\xe0\x30\x69\x1f\xb3\x65\x40\xd7\xa4\x80\xb1\x75\x69\xe3\x74\x7b\x68\x8b\x81\x96\x2e\x1d\x22\x32\xe5\x90\xb4\xe3\xc0\xd0\x7f\x1f\x2e\x65\x59\xb2\x2c\x7f\xc4\x0d\xea\x6d\x98\x5e\x12\xc9\xf7\x8b\xe7\x1e\xde\x43\x69\x36\x83\x18\x85\x54\x08\xad\x58\xf2\x04\x23\x7b\x62\xee\x93\x93\x48\x23\xb7\xd8\x82\x2c\xf3\x67\x33\x68\xf7\xc7\x32\x89\x51\xc3\xd9\x39\x8c\xb8\x89\x78\x02\x6d\xd6\x8b\xd2\x11\xb2\x5f\xe6\xbf\xcc\x0d\x35\x46\x28\x27\xb9\xe5\xe2\xff\x85\x7b\x96\xf9\xbe\x18\xab\x08\x82\x25\xdb\x2c\x83\xa3\x6a\x96\x2c\x0b\xc1\xdc\x27\x3d\x3e\xc1\x20\xb2\x53\x88\x52\x65\x71\x6a\xd9\xdb\xfc\x6f\x08\x81\x33\x67\xbf\xf3\x21\x42\x96\x75\x00\xb5\x4e\x75\x08\x33\xdf\x9b\x70\x0d\x81\xef\x79\x1a\x0d\x85\x60\xd7\x68\xc6\x89\xf5\x3d\xcf\x39\x5c\x57\x32\x9e\xc3\xcb\x6a\x90\x59\x94\x2a\x21\x07\x67\x50\xab\x8c\xe5\xcf\x33\xdf\x0b\x7d\xcf\x4e\x5d\x2e\x5a\x5c\xdd\x2c\xd6\xf4\x1f\xbb\x99\x52\xc5\xa1\xef\x49\xe1\x2c\x7f\x38\x07\x25\x13\xaa\xcc\xd3\x68\xc7\x5a\xd1\xad\x0b\xe2\x7b\x99\xef\x55\x70\xa5\x6a\xbb\xca\xa0\xb6\x0e\x1c\xf6\x81\x47\x77\x7c\x40\xa5\xb1\x1b\xde\x4f\x30\x64\x17\x28\xf8\x38\xb1\x75\xec\x8a\xd4\x17\x79\xfb\x82\x30\xf4\xbd\xd9\xec\x18\x34\x57\x03\x84\xf6\x5f\x1d\x68\x0b\x4a\xd0\x66\xef\x24\x26\xb1\xa1\x2e\x78\x54\x5f\x3d\x0e\x39\xb5\x05\xeb\x59\x3d\x8e\xac\xb3\x25\x9c\x2a\x2b\x28\xca\x65\x3d\x5c\x2d\x92\xee\x05\xb5\xc8\x58\xae\xac\x6b\xcb\xd1\x6a\x86\xd5\x04\x21\x05\xae\x77\x87\x2c\x0b\xa2\x89\xa2\x45\xe0\x50\x97\x02\x54\x6a\xdd\xe3\x71\x92\x10\x32\x90\x65\x94\x09\x15\x85\xdb\x25\xa5\xef\x11\xf6\xb4\xdc\xdc\xc7\xf7\xee\xc7\xa8\x1f\x3b\xc0\xf5\xc0\x10\x54\xc5\x3a\x3f\xd2\xe3\xa0\xec\xe6\xd9\x39\xd8\x29\xbb\x9c\x62\x44\x5d\xee\x40\xc5\xad\x03\x2f\x35\x9a\xf0\xc7\x4d\x5d\xd7\x69\x92\xf4\x79\x74\x17\xcc\x79\x14\x3a\x0e\xc8\x78\x41\x2a\x8d\x86\xfd\xc6\x8d\xcd\x79\xd0\x8d\x83\xad\x44\x6a\x0e\xb9\x02\x67\xf7\x62\x01\x5e\x9b\x75\x2f\x58\xd7\xf4\xac\x96\x6a\x00\x59\x66\xac\x8e\x52\x35\x61\xef\x52\x3d\xe4\xb6\xab\x6c\x40\x05\xbd\x3a\x0d\x09\xd2\xc4\x10\xba\xd2\x3d\x0c\x17\x18\xaf\xf0\x0b\x73\x7e\x5d\xc6\x03\x2c\xe9\x95\xa0\x5a\xa1\x2a\xdd\x63\x9d\x00\xf0\x33\x9c\xe6\xfc\xa2\xb0\x52\x00\x57\x31\x99\x7d\x52\xf2\x7e\x8c\xce\x01\x13\x71\x8d\xc2\xb5\xf7\xe4\x08\xae\x5e\x5f\xc1\x83\xb4\xb7\x60\x30\x11\xa0\x51\xa0\x46\x15\x21\x1c\x9d\xb8\xdc\x9e\x27\x52\x0d\x28\x63\x07\xa9\xab\x72\x97\x3a\xf2\x12\xf2\x22\x2c\x0e\x47\x09\xb7\x8d\x43\xf1\x84\xe0\x42\x6d\x65\xdc\xa2\x95\x1f\xcf\x73\xd6\x39\x44\xfb\xf9\xd3\x28\xe6\x16\x1b\xb7\x0a\xe6\xbb\xba\xb2\x5f\x42\x96\xc7\xf1\xbc\x75\xdb\x0b\xd9\xdb\x34\x19\x0f\xd5\xd2\x26\x43\x19\x97\x9e\x7f\xde\xa2\xc6\x80\x52\x5f\x7e\x6c\x0c\x41\xcd\x5f\x72\x97\x71\x18\x96\x3c\xa7\x6b\x7f\xae\xd3\xb5\x85\x9c\x74\x35\xe0\xf5\xfd\xe0\xda\x88\x16\xb2\x9b\xc7\x11\x36\xe4\xa6\xa7\x75\xe4\x1c\xf0\x6f\x54\x1c\x84\xac\x6b\x68\x16\xed\x5a\xc4\xa1\x00\xe7\x42\x60\x64\x71\x79\xdc\x5c\xa7\x0f\xe6\xcd\xfc\x87\x5a\x41\x7b\x27\x92\x02\x68\x64\x14\xf9\x42\xf8\xe9\x09\xc3\x60\x6b\xba\x97\x97\x5a\x3b\x34\x35\x97\xca\xbe\xe3\x32\xc1\x78\x36\x34\x83\x33\x10\x43\xcb\x7a\x23\x2d\x95\x15\x41\xeb\x4b\x2b\x8f\x3f\x17\x8f\x2f\x2d\x08\x5e\x4c\x42\xe0\x89\x46\x1e\x3f\xd2\x99\x42\xb9\xea\xc0\xa6\xc0\x21\x96\xc2\x4d\x11\x0b\xb9\x5f\xe9\xd6\xca\x3b\x9d\x2d\x2d\x31\x2b\xa6\x95\x9b\x90\x34\x55\x91\xbd\x7f\xfd\x1e\xe0\x90\x03\x88\x62\x72\x4a\x79\x3a\xd7\xc1\x3e\xdd\xbc\x72\x37\xc7\xf3\x22\xbb\xa6\x4b\xbe\x6e\xac\xe7\xf6\x85\x05\x99\x2f\x5c\x8b\x39\xbf\x66\xae\xad\x39\xa7\x6c\xdb\xa8\xf9\x4e\x30\x6b\xfc\x3e\xfc\x5a\x71\xfa\x9c\x17\x97\x65\x5f\x3b\xb0\xab\x79\x9f\xcc\xcb\x6c\x7f\xf0\x64\x8c\xc6\xa9\xd9\xd2\x8c\x2c\xc1\xa8\xc9\x0a\xa9\xc9\xb1\x46\x01\x39\xcc\x06\xec\x2d\x02\x3a\x4d\x93\x0a\xfa\xa9\xbd\x85\x07\xfe\x68\x58\xa9\x33\x95\x34\x48\x79\xea\x69\xaa\x30\x7a\xde\x21\x36\x7d\x33\x51\xaf\x0e\xca\xd3\x67\x13\xca\xbd\x75\x72\x4f\x99\xf4\xff\x59\x7d\xbc\x7a\xfd\xbe\xe8\xe3\xa8\x00\xf2\xc3\xbc\xae\x83\x34\x76\xc4\xae\x74\x10\xee\x2d\xa6\xe5\x42\x9f\x8d\x22\x7b\x1e\x0d\x4a\x7e\x90\xbe\x8f\x3a\xf9\xd0\x7b\xa2\xc8\x17\xc1\xaa\x74\xf9\x26\xb6\x6c\x27\x4b\x0e\xde\xae\x3a\xdf\x28\xf3\xbb\x26\x79\x0e\x8d\xff\x56\x89\x4f\x15\x42\x2a\x60\x55\xe9\x5f\x4c\xf6\xd2\xf9\x3b\x7c\x34\xbb\xad\xa0\x38\x0e\x2c\x6f\xcb\xca\xeb\xc9\x42\x22\x0a\xb5\x59\xd0\xbe\xf2\xea\x95\xa3\x80\x95\x17\xc0\xe2\x65\xec\x8d\x4d\x65\xb0\x7b\x39\x9f\x4f\xbf\xee\x7c\x74\x73\x9f\x1e\xca\x3e\x56\x8a\x5f\x94\x43\x95\x3c\x29\xb9\xdf\x20\x78\xcd\x67\x8e\x7f\xb5\x02\xec\x7b\xda\x6f\xd0\x8d\x15\xd8\x0f\x03\xc9\x26\x44\xbe\xdb\xcb\xd0\x3a\x78\x4a\x2e\xfd\x3f\x36\xff\xab\x63\x53\x35\x7f\x8f\x5b\x6a\xf8\xdb\x74\x38\x94\x36\xd8\xfc\x6d\xad\xf8\xa2\x3a\x7f\x56\xff\x02\xd6\x21\x2b\x3f\xf3\xfd\xf2\xe5\xc6\xdf\xf8\xe9\xbb\x7a\xc6\x29\xbe\x78\x6d\x98\xe3\x6b\x87\xf8\xfc\x60\xd3\x40\x9a\x6d\x94\x59\x86\xa4\xac\xfb\xef\x00\x00\x00\xff\xff\x5f\x7f\x6f\x8c\xb2\x17\x00\x00") func templateDialectSqlCreateTmplBytes() ([]byte, error) { return bindataRead( @@ -519,7 +519,7 @@ func templateDialectSqlCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6061, mode: os.FileMode(420), modTime: time.Unix(1562756996, 0)} + info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6066, mode: os.FileMode(420), modTime: time.Unix(1564676394, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -624,7 +624,7 @@ func templateDialectSqlMetaTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlPredicateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x57\x51\x6f\xe3\x36\x0c\x7e\x76\x7e\x05\x51\x04\x98\x7d\x48\x95\x36\x6d\x5f\x06\x74\x40\xd1\xb5\x40\xb6\xb5\xd9\xd0\xc3\xf6\x50\x14\x07\xcd\xa6\x13\xdd\x1c\xc9\x95\x94\x14\x85\xcf\xff\x7d\xa0\xac\x38\x76\xe2\x5c\x73\x41\x0f\x7b\xd9\x53\xac\x88\x22\xbf\x8f\xfc\x48\xcb\x45\x01\x09\xa6\x42\x22\x1c\x25\x82\x67\x18\xdb\xa1\x79\xce\x86\xb9\xc6\x44\xc4\xdc\xe2\x50\x24\x47\x70\x5c\x96\xbd\x20\x5d\xc8\x38\x34\xf0\xc1\x3c\x67\xec\x01\xc9\x52\xe9\x08\x8a\x5e\x10\x14\xc5\x31\x88\x14\xfa\x6c\xfc\x33\x1b\x9b\x07\xab\x85\x9c\x42\x59\x8a\x64\x00\x9f\xe0\xc7\x4b\x30\x56\xc7\x4a\x2e\xd9\x95\x55\x22\x14\x49\x44\xf6\x28\x13\x20\xaf\x81\x61\x7f\xcd\x50\x63\x48\x6e\x6f\xfe\x08\x0d\xbb\x0e\x8b\xa2\xf2\x75\xad\xa4\xb1\x5c\x5a\x28\xcb\x68\x00\x22\x89\xa2\x5e\x50\xf6\x1a\xa7\x7b\x7b\xa0\x1f\xaa\xdc\x78\x06\x74\xb2\xaf\x72\x82\xd4\x67\x0f\xb1\xca\x91\x4d\xf2\xc6\x16\xd7\xd3\xe6\xde\x95\x9e\xee\xcb\x5c\xe5\xec\x4f\xae\x05\x4f\x44\x5c\xb1\x0a\x86\x43\xda\x90\xca\x02\xd7\xd3\xc5\x1c\xa5\x35\xf0\x82\x1a\x21\xd7\x6a\x29\x12\x4c\x06\xc0\xf3\x9c\x78\xd8\x19\xc2\xed\xd5\x6f\x0f\x37\x10\x7b\xbe\x66\xe0\x3d\x18\x21\x63\x84\x17\x84\x98\xcb\x1f\x2c\x1d\xc8\x5e\xe1\x68\x7c\x0f\x61\x74\xc4\xe0\xe3\x4c\x18\x78\x11\x59\x06\x73\xfe\x0f\x82\xa5\x65\xcd\x1c\x52\x9e\x99\x57\x46\x8e\x44\x0a\x19\x4a\x97\x55\x62\x58\x96\x11\x5c\x5e\xc2\x89\x23\xd0\xce\xff\x2d\xcf\x0c\x86\x94\xe6\x20\x08\x34\xda\x85\x96\xf4\xe8\x08\x2d\x29\x35\x14\x28\x7c\x7c\x12\xd2\xa2\x4e\x79\x8c\x45\x39\xd8\xf4\xed\x0e\xa7\x4a\x83\xa0\x03\x9a\xcb\x29\xc2\xd2\xc7\x2a\x8a\x2e\x9d\x2c\x1f\xc5\x13\x29\x65\x43\x28\x6b\x9f\x8f\xe2\x29\x2a\x0a\xc0\xcc\xa0\x37\x87\x4b\x68\x6d\xd3\xee\x4a\x50\x0e\xae\x13\x09\xd9\x77\xc4\x73\x6c\xba\xa4\xd9\x60\xb1\x72\xd1\xa5\x52\x32\x53\x39\xbb\xe7\x73\x82\xf3\x15\xc5\x2e\x3d\xdf\xb6\x3a\x18\x63\x35\xdc\x03\x14\x9d\x0a\xcc\x92\xa6\xa0\xd3\xa6\x66\x6f\x69\xf7\x2d\xd5\xee\x68\xb9\x74\x13\xfe\xa1\xe8\x36\x5b\x6e\x17\xc2\xff\xfb\xf1\xf0\x7e\xfc\x56\x75\x6e\x15\xf7\x7b\x68\x13\x93\x29\x0e\x67\xbc\x55\x7c\x6c\x96\xf0\x26\x99\xe2\xbe\x35\x44\x76\x37\xba\x03\x5f\x3e\x7b\xea\xba\x95\x7d\xe4\x7f\x67\x18\xba\x84\xac\x48\x57\x59\x7b\xce\xd8\x58\x56\xcf\x81\x3d\xdd\xd5\x92\xd5\xfe\x3a\xa6\xb3\x42\xf6\xfb\xaf\x0d\xab\x47\x9f\x19\x64\x63\x33\x96\x4b\xd4\x6e\xea\x9c\xae\x07\xd0\x49\x9d\xa2\xa7\x88\xdd\x6a\x35\x77\x79\xaf\x90\x55\xfe\xdc\x73\x33\xb0\x8f\x5c\xfd\x44\x1b\xf3\x49\xe9\x8a\xec\x04\x42\x2e\x13\x7a\x9e\x8c\x26\xad\xf8\x11\x94\x65\x51\x0c\x3f\x00\x19\x7d\xf9\x02\x21\x19\xbc\x08\x3b\x03\xe1\x01\x52\xe6\x23\xf8\x30\x7c\x33\x5b\x04\xf5\x5e\xd9\xfb\x45\x96\x85\x75\x9e\x90\x5d\xab\x6c\x31\x97\x2d\xc8\x2d\x98\x3e\xfe\x64\x74\xd7\x8e\xcf\x8d\x51\xf1\xfe\xd1\xdf\xa1\x56\xdb\x48\x59\x65\x19\xec\x59\x8a\x95\xf9\x76\x3e\x76\xa6\xa2\xb3\x7a\xbe\xf9\x0e\x6c\x11\xca\xde\xfb\xb7\x09\x31\x70\xef\xdd\x53\x57\x31\xe8\x7f\xa6\xc5\x89\x5b\x1c\x77\xa8\xba\xb2\x5f\x59\x90\x79\x7d\x94\x18\x1d\xef\x2c\xa8\x1d\xb9\xbf\xea\x64\xfb\xd7\xbb\x8b\x21\x11\xfa\xd5\xdf\xae\x00\xaf\xb9\xaf\xc2\xca\x5d\x05\x13\x99\x87\xb1\x59\xa1\xda\x95\x13\x5e\x7d\xc6\x99\xad\xf7\xd6\xe8\x2a\x3c\x67\x6d\x3c\x3b\x8a\xef\x4c\xcf\x57\xa6\x5e\x57\xf6\xac\x6e\x83\xad\x41\xd0\xff\xec\xda\xdc\x8b\xc6\x29\xcc\x9e\xf9\xd5\x2f\x4a\xc8\xd0\x8e\xfc\x6a\x22\xbf\xee\x48\x38\x47\x03\xb0\xa3\xda\xc8\xa5\x66\x43\xf6\x15\xc4\x8b\x0d\x88\x7e\xce\xd8\x51\x7d\xbb\xfa\x34\x80\x7c\x7d\xc1\x22\x7d\x19\xff\x02\xc9\x43\x7b\x11\xd5\xd7\x36\x7b\xee\x8e\xae\xa8\x5e\x6c\x0d\x83\xb1\x0c\x77\xf7\x20\xd8\xf3\xe8\x3f\x19\x57\x6b\x7d\xb5\x9a\xbf\x2b\x63\x9b\x23\xf8\xfb\x4b\xb1\x5b\x5c\x9d\xda\xdc\xaf\x5e\xa3\x75\xbd\x76\x95\xa6\x6b\x2e\x91\x98\xde\x75\x4c\xef\xc8\x7a\xc7\xc8\xdd\x73\xd6\xbe\x17\xfb\x0e\x61\x36\x98\x1f\x36\x89\x95\x7e\xf3\xc3\xd6\x7d\xc6\x6c\x41\x77\xc7\x3d\x7e\x91\x82\x80\x9f\x1a\x97\xb7\x89\x0e\xd7\x74\xf2\xd0\xd0\xe2\xdb\xb1\x49\x65\xdf\x04\x97\x87\x86\xde\x5c\xe1\xd6\x3d\xed\xdf\x00\x00\x00\xff\xff\x06\x03\xfc\x02\xd3\x0f\x00\x00") +var _templateDialectSqlPredicateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x57\x4f\x6f\xe3\xb6\x13\x3d\xcb\x9f\x62\x10\x18\xf8\x51\x81\x43\x27\x4e\x72\xf9\x01\x29\x10\xa4\x09\xe0\xb6\x89\x5b\x64\xd1\x1e\x82\x60\xc1\x4a\x23\x9b\x5b\x99\x54\x48\xda\x41\xa0\xd5\x77\x2f\x48\xd1\xfa\x63\x4b\x1b\xaf\x91\xa2\x97\x9e\x2c\x9a\xc3\x99\xf7\x66\xde\x8c\xa8\x3c\x87\x18\x13\x2e\x10\x8e\x62\xce\x52\x8c\xcc\x58\xbf\xa4\xe3\x4c\x61\xcc\x23\x66\x70\xcc\xe3\x23\x38\x29\x8a\x41\x90\xac\x44\x44\x34\x1c\xeb\x97\x94\x3e\xa2\xb5\x94\x2a\x84\x7c\x10\x04\x79\x7e\x02\x3c\x81\x21\x9d\xfe\x48\xa7\xfa\xd1\x28\x2e\xe6\x50\x14\x3c\x1e\xc1\x67\xf8\xff\x15\x68\xa3\x22\x29\xd6\xf4\xda\x48\x4e\x78\x1c\x5a\x7b\x14\x31\x58\xaf\x81\xa6\x7f\x2c\x50\x21\xb1\x6e\x6f\x7f\x23\x9a\xde\x90\x3c\x2f\x7d\xdd\x48\xa1\x0d\x13\x06\x8a\x22\x1c\x01\x8f\xc3\x70\x10\x14\x83\xc6\xe9\xc1\x1e\xe8\xc7\x32\xd3\x9e\x81\x3d\x39\x94\x99\x85\x34\xa4\x8f\x91\xcc\x90\xce\xb2\xc6\x16\x53\xf3\xe6\xde\xb5\x9a\xef\xcb\x5c\x66\xf4\x77\xa6\x38\x8b\x79\x54\xb2\x0a\xc6\x63\xbb\x21\xa4\x01\xa6\xe6\xab\x25\x0a\xa3\xe1\x15\x15\x42\xa6\xe4\x9a\xc7\x18\x8f\x80\x65\x99\xe5\x61\x16\x08\x77\xd7\xbf\x3c\xde\x42\xe4\xf9\xea\x91\xf7\xa0\xb9\x88\x10\x5e\x11\x22\x26\xfe\x67\xec\x81\xf4\x0d\x8e\xa6\x0f\x40\xc2\x23\x0a\x9f\x16\x5c\xc3\x2b\x4f\x53\x58\xb2\xbf\x10\x8c\x5d\x56\xcc\x21\x61\xa9\x7e\xa3\xd6\x11\x4f\x20\x45\xe1\xb2\x6a\x19\x16\x45\x08\x57\x57\x70\xea\x08\xb4\xf3\x7f\xc7\x52\x8d\xc4\xa6\x39\x08\x02\x85\x66\xa5\x84\x7d\x74\x84\xd6\x36\x35\x36\x10\x79\x7a\xe6\xc2\xa0\x4a\x58\x84\x79\x31\xda\xf6\xed\x0e\x27\x52\x01\xb7\x07\x14\x13\x73\x84\xb5\x8f\x95\xe7\x5d\x3a\x59\x3f\xf1\x67\xab\x94\x2d\xa1\xd4\x3e\x9f\xf8\x73\x98\xe7\x80\xa9\x46\x6f\x0e\x57\xd0\xda\xb6\xbb\x1b\x41\x39\xb8\x4e\x24\xd6\xbe\x23\x9e\xcb\x49\xa7\x36\x1b\x34\x36\x3e\xba\x64\x6a\xcd\x64\x46\x1f\xd8\xd2\xe2\xf9\x86\x64\x3d\xdf\xb6\x3a\xd6\x94\xd2\x9a\x0d\x8f\x2b\xec\x07\xc8\x3b\xe1\x98\xc6\x4d\x75\x27\x4d\x01\xdf\xd9\xdd\xf7\x24\xdc\xd3\x7f\xc9\x16\x95\xf5\xa1\xe8\xb6\xfb\xaf\x0f\xe1\x7f\xcd\x79\x78\x73\x7e\xaf\x52\x77\x8a\xdb\x29\x54\xaf\xd3\x43\xb5\x89\xf1\x1c\xc7\x0b\xd6\x2a\x3e\x36\x4b\x78\x1b\xcf\x71\xdf\x1a\x22\xbd\x9f\xdc\x83\x2f\x9f\x39\x73\x9d\x4b\x3f\xb1\x3f\x53\x24\x2e\x21\x1b\xd2\x65\xd6\x5e\x52\x3a\x15\xe5\x73\x60\xce\xfa\xda\xb3\xdc\xaf\x63\x3a\x2b\xa4\xbf\xfe\xdc\xb0\x7a\xf2\x99\x41\x3a\xd5\x53\xb1\x46\xe5\x9a\xf6\xac\xee\xdf\xd3\x2a\x45\xcf\x21\xbd\x53\x72\xe9\xf2\x5e\x22\x2b\xfd\xb9\xe7\x66\x60\x1f\xb9\xfc\x09\xb7\x86\x95\x54\x25\xd9\x19\x10\x26\x62\xfb\x3c\x9b\xcc\x5a\xf1\x43\x28\x8a\x3c\x1f\x1f\x83\x35\xfa\xfa\x15\x88\x35\x78\xe5\x66\x01\xdc\x03\xb4\x99\x0f\xe1\x78\xfc\x6e\xb6\x2c\xd4\x07\x69\x1e\x56\x69\x4a\xaa\x3c\x21\xbd\x91\xe9\x6a\x29\x5a\x90\x5b\x30\x7d\xfc\xd9\xe4\xbe\x1d\x9f\x69\x2d\xa3\xfd\xa3\x7f\x40\xad\x76\x91\xd2\xd2\x32\xd8\xb3\x14\x1b\xf3\xdd\x7c\xf4\xa6\xa2\xb3\x7a\xbe\xf9\x0e\x6c\x11\x9b\xbd\x8f\x6f\x13\xcb\xc0\xbd\x84\xcf\x5c\xc5\x60\xf8\xc5\x2e\x4e\xdd\xe2\xa4\x43\xd5\xa5\xfd\xc6\xc2\x9a\x57\x47\x2d\xa3\x93\xde\x82\x9a\x89\xfb\xab\x4a\xb6\x7f\xd7\xbb\x18\x02\x61\x58\xfe\xed\x0a\xf0\x96\xf9\x2a\x6c\xdc\x95\x30\x91\x7a\x18\xdb\x15\xaa\x5c\x39\xe1\x55\x67\x9c\x59\xbd\x57\xa3\x2b\xf1\x9c\xb7\xf1\xf4\x14\xdf\x99\x5e\x6c\x4c\xbd\xae\xcc\x79\xd5\x06\x3b\x83\x60\xf8\xc5\xb5\xb9\x17\x8d\x53\x98\x39\xf7\xab\x9f\x24\x17\xc4\x4c\xfc\x6a\x26\xbe\xed\x88\x3b\x47\x23\x30\x93\xca\xc8\xa5\x66\x4b\xf6\x25\xc4\xcb\x2d\x88\x7e\xce\x98\x49\x75\xd5\xfa\x3c\x82\xac\xbe\x6d\x59\x7d\x69\xff\x02\xc9\x88\xb9\x0c\xab\x3b\x9c\xb9\x70\x47\x37\x54\x2f\x77\x86\xc1\x54\x90\xfe\x1e\x04\x73\x11\xfe\x2b\xe3\xaa\xd6\x57\xab\xf9\xbb\x32\xb6\x3d\x82\xff\x79\x29\x76\x8b\xab\x53\x9b\xfb\xd5\x6b\x52\xd7\xab\xaf\x34\x5d\x73\xc9\x8a\xe9\x43\xc7\x74\x4f\xd6\x3b\x46\xee\x9e\xb3\xf6\xa3\xd8\x77\x08\xb3\xc1\xfc\xb0\x49\x2c\xd5\xbb\x5f\xb9\xee\x9b\x66\x07\xba\x3b\xee\xf1\xf3\x04\x38\xfc\xd0\xb8\xbc\xcd\x14\xa9\xe9\x64\x44\xdb\xc5\xf7\x63\x13\xd2\xbc\x0b\x2e\x23\xda\xbe\xb9\xc8\xce\x3d\xed\xef\x00\x00\x00\xff\xff\x2f\x58\x90\xb0\xe0\x0f\x00\x00") func templateDialectSqlPredicateTmplBytes() ([]byte, error) { return bindataRead( @@ -639,7 +639,7 @@ func templateDialectSqlPredicateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/predicate.tmpl", size: 4051, mode: os.FileMode(420), modTime: time.Unix(1564480239, 0)} + info := bindataFileInfo{name: "template/dialect/sql/predicate.tmpl", size: 4064, mode: os.FileMode(420), modTime: time.Unix(1564676224, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/graph.go b/entc/gen/graph.go index be35b9c7c..64759da2e 100644 --- a/entc/gen/graph.go +++ b/entc/gen/graph.go @@ -27,6 +27,9 @@ type ( Header string // Storage to support in codegen. Storage []*Storage + // IDType specifies the type of the id field in the codegen. + // The supported types are string and int, which also the default. + IDType field.Type } // Graph holds the nodes/entities of the loaded graph schema. Note that, it doesn't // hold the edges of the graph. Instead, each Type holds the edges for other Types. diff --git a/entc/gen/template/dialect/sql/create.tmpl b/entc/gen/template/dialect/sql/create.tmpl index 987a7fca1..8e902a2e3 100644 --- a/entc/gen/template/dialect/sql/create.tmpl +++ b/entc/gen/template/dialect/sql/create.tmpl @@ -26,7 +26,7 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name if err != nil { return nil, rollback(tx, err) } - {{ $.Receiver }}.ID = {{ if $.ID.IsString }}strconv.FormatInt(id, 10){{ else }}id{{ end }} + {{ $.Receiver }}.ID = {{ if $.ID.IsString }}strconv.FormatInt(id, 10){{ else }}int(id){{ end }} {{- range $_, $e := $.Edges }} if len({{ $receiver }}.{{ $e.StructField }}) > 0 { {{- if and $e.Unique $e.SelfRef }}{{/* O2O with self reference */}} diff --git a/entc/gen/template/dialect/sql/predicate.tmpl b/entc/gen/template/dialect/sql/predicate.tmpl index fb2796ea5..a536a4ade 100644 --- a/entc/gen/template/dialect/sql/predicate.tmpl +++ b/entc/gen/template/dialect/sql/predicate.tmpl @@ -21,9 +21,9 @@ {{ if $.ID.IsString }}v[i], _ = strconv.Atoi({{ $arg }}[i]){{ else }}v[i] = {{ $arg }}[i]{{ end }} } {{- else if $.ID.IsString }} - v, _ := strconv.Atoi({{ $arg }}) + id, _ := strconv.Atoi({{ $arg }}) {{- end }} - s.Where(sql.{{ $op.Name }}(s.C({{ $.ID.Constant }}), v{{ if $op.Variadic }}...{{ end }})) + s.Where(sql.{{ $op.Name }}(s.C({{ $.ID.Constant }}), {{ if $op.Variadic }}v...{{ else }}id{{ end }})) } {{- end }} diff --git a/entc/gen/type.go b/entc/gen/type.go index 10951fe1e..1004862e4 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -101,7 +101,7 @@ func NewType(c Config, schema *load.Schema) (*Type, error) { Name: schema.Name, ID: &Field{ Name: "id", - Type: field.TypeString, + Type: c.IDType, StructTag: `json:"id,omitempty"`, }, } diff --git a/entc/integration/ent/card/where.go b/entc/integration/ent/card/where.go index c464c2788..30bd720c5 100644 --- a/entc/integration/ent/card/where.go +++ b/entc/integration/ent/card/where.go @@ -30,8 +30,8 @@ func ID(id string) predicate.Card { func IDEQ(id string) predicate.Card { return predicate.CardPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -43,8 +43,8 @@ func IDEQ(id string) predicate.Card { func IDNEQ(id string) predicate.Card { return predicate.CardPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -56,8 +56,8 @@ func IDNEQ(id string) predicate.Card { func IDGT(id string) predicate.Card { return predicate.CardPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -69,8 +69,8 @@ func IDGT(id string) predicate.Card { func IDGTE(id string) predicate.Card { return predicate.CardPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -82,8 +82,8 @@ func IDGTE(id string) predicate.Card { func IDLT(id string) predicate.Card { return predicate.CardPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -95,8 +95,8 @@ func IDLT(id string) predicate.Card { func IDLTE(id string) predicate.Card { return predicate.CardPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/ent/comment/where.go b/entc/integration/ent/comment/where.go index 556a9a177..3c5ba7592 100644 --- a/entc/integration/ent/comment/where.go +++ b/entc/integration/ent/comment/where.go @@ -30,8 +30,8 @@ func ID(id string) predicate.Comment { func IDEQ(id string) predicate.Comment { return predicate.CommentPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -43,8 +43,8 @@ func IDEQ(id string) predicate.Comment { func IDNEQ(id string) predicate.Comment { return predicate.CommentPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -56,8 +56,8 @@ func IDNEQ(id string) predicate.Comment { func IDGT(id string) predicate.Comment { return predicate.CommentPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -69,8 +69,8 @@ func IDGT(id string) predicate.Comment { func IDGTE(id string) predicate.Comment { return predicate.CommentPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -82,8 +82,8 @@ func IDGTE(id string) predicate.Comment { func IDLT(id string) predicate.Comment { return predicate.CommentPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -95,8 +95,8 @@ func IDLT(id string) predicate.Comment { func IDLTE(id string) predicate.Comment { return predicate.CommentPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/ent/fieldtype/where.go b/entc/integration/ent/fieldtype/where.go index 3a9e22e38..e39c2a930 100644 --- a/entc/integration/ent/fieldtype/where.go +++ b/entc/integration/ent/fieldtype/where.go @@ -30,8 +30,8 @@ func ID(id string) predicate.FieldType { func IDEQ(id string) predicate.FieldType { return predicate.FieldTypePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -43,8 +43,8 @@ func IDEQ(id string) predicate.FieldType { func IDNEQ(id string) predicate.FieldType { return predicate.FieldTypePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -56,8 +56,8 @@ func IDNEQ(id string) predicate.FieldType { func IDGT(id string) predicate.FieldType { return predicate.FieldTypePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -69,8 +69,8 @@ func IDGT(id string) predicate.FieldType { func IDGTE(id string) predicate.FieldType { return predicate.FieldTypePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -82,8 +82,8 @@ func IDGTE(id string) predicate.FieldType { func IDLT(id string) predicate.FieldType { return predicate.FieldTypePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -95,8 +95,8 @@ func IDLT(id string) predicate.FieldType { func IDLTE(id string) predicate.FieldType { return predicate.FieldTypePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/ent/file/where.go b/entc/integration/ent/file/where.go index 6abc3ef9f..ee99a473b 100644 --- a/entc/integration/ent/file/where.go +++ b/entc/integration/ent/file/where.go @@ -30,8 +30,8 @@ func ID(id string) predicate.File { func IDEQ(id string) predicate.File { return predicate.FilePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -43,8 +43,8 @@ func IDEQ(id string) predicate.File { func IDNEQ(id string) predicate.File { return predicate.FilePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -56,8 +56,8 @@ func IDNEQ(id string) predicate.File { func IDGT(id string) predicate.File { return predicate.FilePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -69,8 +69,8 @@ func IDGT(id string) predicate.File { func IDGTE(id string) predicate.File { return predicate.FilePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -82,8 +82,8 @@ func IDGTE(id string) predicate.File { func IDLT(id string) predicate.File { return predicate.FilePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -95,8 +95,8 @@ func IDLT(id string) predicate.File { func IDLTE(id string) predicate.File { return predicate.FilePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/ent/group/where.go b/entc/integration/ent/group/where.go index 6efbf801b..23de3337c 100644 --- a/entc/integration/ent/group/where.go +++ b/entc/integration/ent/group/where.go @@ -31,8 +31,8 @@ func ID(id string) predicate.Group { func IDEQ(id string) predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -44,8 +44,8 @@ func IDEQ(id string) predicate.Group { func IDNEQ(id string) predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -57,8 +57,8 @@ func IDNEQ(id string) predicate.Group { func IDGT(id string) predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -70,8 +70,8 @@ func IDGT(id string) predicate.Group { func IDGTE(id string) predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -83,8 +83,8 @@ func IDGTE(id string) predicate.Group { func IDLT(id string) predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -96,8 +96,8 @@ func IDLT(id string) predicate.Group { func IDLTE(id string) predicate.Group { return predicate.GroupPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/ent/groupinfo/where.go b/entc/integration/ent/groupinfo/where.go index 8980922e5..332245e9b 100644 --- a/entc/integration/ent/groupinfo/where.go +++ b/entc/integration/ent/groupinfo/where.go @@ -30,8 +30,8 @@ func ID(id string) predicate.GroupInfo { func IDEQ(id string) predicate.GroupInfo { return predicate.GroupInfoPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -43,8 +43,8 @@ func IDEQ(id string) predicate.GroupInfo { func IDNEQ(id string) predicate.GroupInfo { return predicate.GroupInfoPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -56,8 +56,8 @@ func IDNEQ(id string) predicate.GroupInfo { func IDGT(id string) predicate.GroupInfo { return predicate.GroupInfoPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -69,8 +69,8 @@ func IDGT(id string) predicate.GroupInfo { func IDGTE(id string) predicate.GroupInfo { return predicate.GroupInfoPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -82,8 +82,8 @@ func IDGTE(id string) predicate.GroupInfo { func IDLT(id string) predicate.GroupInfo { return predicate.GroupInfoPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -95,8 +95,8 @@ func IDLT(id string) predicate.GroupInfo { func IDLTE(id string) predicate.GroupInfo { return predicate.GroupInfoPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/ent/node/where.go b/entc/integration/ent/node/where.go index d4e037489..4715ebac3 100644 --- a/entc/integration/ent/node/where.go +++ b/entc/integration/ent/node/where.go @@ -30,8 +30,8 @@ func ID(id string) predicate.Node { func IDEQ(id string) predicate.Node { return predicate.NodePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -43,8 +43,8 @@ func IDEQ(id string) predicate.Node { func IDNEQ(id string) predicate.Node { return predicate.NodePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -56,8 +56,8 @@ func IDNEQ(id string) predicate.Node { func IDGT(id string) predicate.Node { return predicate.NodePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -69,8 +69,8 @@ func IDGT(id string) predicate.Node { func IDGTE(id string) predicate.Node { return predicate.NodePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -82,8 +82,8 @@ func IDGTE(id string) predicate.Node { func IDLT(id string) predicate.Node { return predicate.NodePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -95,8 +95,8 @@ func IDLT(id string) predicate.Node { func IDLTE(id string) predicate.Node { return predicate.NodePerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/ent/pet/where.go b/entc/integration/ent/pet/where.go index bc49a6ee1..a310655bb 100644 --- a/entc/integration/ent/pet/where.go +++ b/entc/integration/ent/pet/where.go @@ -30,8 +30,8 @@ func ID(id string) predicate.Pet { func IDEQ(id string) predicate.Pet { return predicate.PetPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -43,8 +43,8 @@ func IDEQ(id string) predicate.Pet { func IDNEQ(id string) predicate.Pet { return predicate.PetPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -56,8 +56,8 @@ func IDNEQ(id string) predicate.Pet { func IDGT(id string) predicate.Pet { return predicate.PetPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -69,8 +69,8 @@ func IDGT(id string) predicate.Pet { func IDGTE(id string) predicate.Pet { return predicate.PetPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -82,8 +82,8 @@ func IDGTE(id string) predicate.Pet { func IDLT(id string) predicate.Pet { return predicate.PetPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -95,8 +95,8 @@ func IDLT(id string) predicate.Pet { func IDLTE(id string) predicate.Pet { return predicate.PetPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/ent/user/where.go b/entc/integration/ent/user/where.go index b8936cc9c..7cb60d27f 100644 --- a/entc/integration/ent/user/where.go +++ b/entc/integration/ent/user/where.go @@ -30,8 +30,8 @@ func ID(id string) predicate.User { func IDEQ(id string) predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.EQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.EQ(id)) @@ -43,8 +43,8 @@ func IDEQ(id string) predicate.User { func IDNEQ(id string) predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.NEQ(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.NEQ(id)) @@ -56,8 +56,8 @@ func IDNEQ(id string) predicate.User { func IDGT(id string) predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GT(id)) @@ -69,8 +69,8 @@ func IDGT(id string) predicate.User { func IDGTE(id string) predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.GTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.GTE(id)) @@ -82,8 +82,8 @@ func IDGTE(id string) predicate.User { func IDLT(id string) predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LT(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LT(id)) @@ -95,8 +95,8 @@ func IDLT(id string) predicate.User { func IDLTE(id string) predicate.User { return predicate.UserPerDialect( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + id, _ := strconv.Atoi(id) + s.Where(sql.LTE(s.C(FieldID), id)) }, func(t *dsl.Traversal) { t.HasID(p.LTE(id)) diff --git a/entc/integration/generate.go b/entc/integration/generate.go index fcb13afb5..4b2039101 100644 --- a/entc/integration/generate.go +++ b/entc/integration/generate.go @@ -1,5 +1,5 @@ package integration -//go:generate go run ../cmd/entc/entc.go generate --storage=sql,gremlin ./ent/schema +//go:generate go run ../cmd/entc/entc.go generate --storage=sql,gremlin --idtype=string ./ent/schema //go:generate go run ../cmd/entc/entc.go generate ./migrate/entv1/schema //go:generate go run ../cmd/entc/entc.go generate ./migrate/entv2/schema diff --git a/entc/integration/migrate/entv1/client.go b/entc/integration/migrate/entv1/client.go index 86094445b..0e5c53be7 100644 --- a/entc/integration/migrate/entv1/client.go +++ b/entc/integration/migrate/entv1/client.go @@ -74,7 +74,7 @@ func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { } // UpdateOneID returns an update builder for the given id. -func (c *UserClient) UpdateOneID(id string) *UserUpdateOne { +func (c *UserClient) UpdateOneID(id int) *UserUpdateOne { return &UserUpdateOne{config: c.config, id: id} } @@ -89,7 +89,7 @@ func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { } // DeleteOneID returns a delete builder for the given id. -func (c *UserClient) DeleteOneID(id string) *UserDeleteOne { +func (c *UserClient) DeleteOneID(id int) *UserDeleteOne { return &UserDeleteOne{c.Delete().Where(user.ID(id))} } diff --git a/entc/integration/migrate/entv1/ent.go b/entc/integration/migrate/entv1/ent.go index eb55a8be8..faf1e3619 100644 --- a/entc/integration/migrate/entv1/ent.go +++ b/entc/integration/migrate/entv1/ent.go @@ -183,8 +183,8 @@ func rollback(tx dialect.Tx, err error) error { } // keys returns the keys/ids from the edge map. -func keys(m map[string]struct{}) []string { - s := make([]string, 0, len(m)) +func keys(m map[int]struct{}) []int { + s := make([]int, 0, len(m)) for id, _ := range m { s = append(s, id) } diff --git a/entc/integration/migrate/entv1/user.go b/entc/integration/migrate/entv1/user.go index fe754e7c7..355481ae3 100644 --- a/entc/integration/migrate/entv1/user.go +++ b/entc/integration/migrate/entv1/user.go @@ -5,7 +5,6 @@ package entv1 import ( "bytes" "fmt" - "strconv" "fbc/ent/dialect/sql" ) @@ -14,7 +13,7 @@ import ( type User struct { config // ID of the ent. - ID string `json:"id,omitempty"` + ID int `json:"id,omitempty"` // Age holds the value of the "age" field. Age int32 `json:"age,omitempty"` // Name holds the value of the "name" field. @@ -40,7 +39,7 @@ func (u *User) FromRows(rows *sql.Rows) error { ); err != nil { return err } - u.ID = strconv.Itoa(vu.ID) + u.ID = vu.ID u.Age = vu.Age u.Name = vu.Name u.Address = vu.Address.String @@ -77,12 +76,6 @@ func (u *User) String() string { return buf.String() } -// id returns the int representation of the ID field. -func (u *User) id() int { - id, _ := strconv.Atoi(u.ID) - return id -} - // Users is a parsable slice of User. type Users []*User diff --git a/entc/integration/migrate/entv1/user/where.go b/entc/integration/migrate/entv1/user/where.go index 06749a732..bfcf39617 100644 --- a/entc/integration/migrate/entv1/user/where.go +++ b/entc/integration/migrate/entv1/user/where.go @@ -3,85 +3,76 @@ package user import ( - "strconv" - "fbc/ent/entc/integration/migrate/entv1/predicate" "fbc/ent/dialect/sql" ) // ID filters vertices based on their identifier. -func ID(id string) predicate.User { +func ID(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id string) predicate.User { +func IDEQ(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id string) predicate.User { +func IDNEQ(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + s.Where(sql.NEQ(s.C(FieldID), id)) }, ) } // IDGT applies the GT predicate on the ID field. -func IDGT(id string) predicate.User { +func IDGT(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + s.Where(sql.GT(s.C(FieldID), id)) }, ) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id string) predicate.User { +func IDGTE(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + s.Where(sql.GTE(s.C(FieldID), id)) }, ) } // IDLT applies the LT predicate on the ID field. -func IDLT(id string) predicate.User { +func IDLT(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + s.Where(sql.LT(s.C(FieldID), id)) }, ) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id string) predicate.User { +func IDLTE(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + s.Where(sql.LTE(s.C(FieldID), id)) }, ) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...string) predicate.User { +func IDIn(ids ...int) predicate.User { return predicate.User( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -92,7 +83,7 @@ func IDIn(ids ...string) predicate.User { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.In(s.C(FieldID), v...)) }, @@ -100,7 +91,7 @@ func IDIn(ids ...string) predicate.User { } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...string) predicate.User { +func IDNotIn(ids ...int) predicate.User { return predicate.User( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -111,7 +102,7 @@ func IDNotIn(ids ...string) predicate.User { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.NotIn(s.C(FieldID), v...)) }, diff --git a/entc/integration/migrate/entv1/user_create.go b/entc/integration/migrate/entv1/user_create.go index 9ea963c09..bd08c622b 100644 --- a/entc/integration/migrate/entv1/user_create.go +++ b/entc/integration/migrate/entv1/user_create.go @@ -6,7 +6,6 @@ import ( "context" "errors" "fmt" - "strconv" "fbc/ent/entc/integration/migrate/entv1/user" @@ -106,7 +105,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { if err != nil { return nil, rollback(tx, err) } - u.ID = strconv.FormatInt(id, 10) + u.ID = int(id) if err := tx.Commit(); err != nil { return nil, err } diff --git a/entc/integration/migrate/entv1/user_query.go b/entc/integration/migrate/entv1/user_query.go index 96ba19a9c..10965c071 100644 --- a/entc/integration/migrate/entv1/user_query.go +++ b/entc/integration/migrate/entv1/user_query.go @@ -52,12 +52,12 @@ func (uq *UserQuery) Order(o ...Order) *UserQuery { } // Get returns a User entity by its id. -func (uq *UserQuery) Get(ctx context.Context, id string) (*User, error) { +func (uq *UserQuery) Get(ctx context.Context, id int) (*User, error) { return uq.Where(user.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. -func (uq *UserQuery) GetX(ctx context.Context, id string) *User { +func (uq *UserQuery) GetX(ctx context.Context, id int) *User { u, err := uq.Get(ctx, id) if err != nil { panic(err) @@ -87,8 +87,8 @@ func (uq *UserQuery) FirstX(ctx context.Context) *User { } // FirstID returns the first User id in the query. Returns *ErrNotFound when no id was found. -func (uq *UserQuery) FirstID(ctx context.Context) (id string, err error) { - var ids []string +func (uq *UserQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = uq.Limit(1).IDs(ctx); err != nil { return } @@ -100,7 +100,7 @@ func (uq *UserQuery) FirstID(ctx context.Context) (id string, err error) { } // FirstXID is like FirstID, but panics if an error occurs. -func (uq *UserQuery) FirstXID(ctx context.Context) string { +func (uq *UserQuery) FirstXID(ctx context.Context) int { id, err := uq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -134,8 +134,8 @@ func (uq *UserQuery) OnlyX(ctx context.Context) *User { } // OnlyID returns the only User id in the query, returns an error if not exactly one id was returned. -func (uq *UserQuery) OnlyID(ctx context.Context) (id string, err error) { - var ids []string +func (uq *UserQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = uq.Limit(2).IDs(ctx); err != nil { return } @@ -151,7 +151,7 @@ func (uq *UserQuery) OnlyID(ctx context.Context) (id string, err error) { } // OnlyXID is like OnlyID, but panics if an error occurs. -func (uq *UserQuery) OnlyXID(ctx context.Context) string { +func (uq *UserQuery) OnlyXID(ctx context.Context) int { id, err := uq.OnlyID(ctx) if err != nil { panic(err) @@ -179,7 +179,7 @@ func (uq *UserQuery) AllX(ctx context.Context) []*User { } // IDs executes the query and returns a list of User ids. -func (uq *UserQuery) IDs(ctx context.Context) ([]string, error) { +func (uq *UserQuery) IDs(ctx context.Context) ([]int, error) { switch uq.driver.Dialect() { case dialect.MySQL, dialect.SQLite: return uq.sqlIDs(ctx) @@ -189,7 +189,7 @@ func (uq *UserQuery) IDs(ctx context.Context) ([]string, error) { } // IDsX is like IDs, but panics if an error occurs. -func (uq *UserQuery) IDsX(ctx context.Context) []string { +func (uq *UserQuery) IDsX(ctx context.Context) []int { ids, err := uq.IDs(ctx) if err != nil { panic(err) @@ -325,12 +325,12 @@ func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) { return n > 0, nil } -func (uq *UserQuery) sqlIDs(ctx context.Context) ([]string, error) { +func (uq *UserQuery) sqlIDs(ctx context.Context) ([]int, error) { vs, err := uq.sqlAll(ctx) if err != nil { return nil, err } - var ids []string + var ids []int for _, v := range vs { ids = append(ids, v.ID) } diff --git a/entc/integration/migrate/entv1/user_update.go b/entc/integration/migrate/entv1/user_update.go index 790c51bbd..1aca2ba8d 100644 --- a/entc/integration/migrate/entv1/user_update.go +++ b/entc/integration/migrate/entv1/user_update.go @@ -151,7 +151,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { // UserUpdateOne is the builder for updating a single User entity. type UserUpdateOne struct { config - id string + id int age *int32 name *string address *string @@ -236,7 +236,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) { if err := u.FromRows(rows); err != nil { return nil, fmt.Errorf("entv1: failed scanning row into User: %v", err) } - id = u.id() + id = u.ID ids = append(ids, id) } switch n := len(ids); { diff --git a/entc/integration/migrate/entv2/client.go b/entc/integration/migrate/entv2/client.go index a01036bc7..f956cb9f5 100644 --- a/entc/integration/migrate/entv2/client.go +++ b/entc/integration/migrate/entv2/client.go @@ -84,7 +84,7 @@ func (c *GroupClient) UpdateOne(gr *Group) *GroupUpdateOne { } // UpdateOneID returns an update builder for the given id. -func (c *GroupClient) UpdateOneID(id string) *GroupUpdateOne { +func (c *GroupClient) UpdateOneID(id int) *GroupUpdateOne { return &GroupUpdateOne{config: c.config, id: id} } @@ -99,7 +99,7 @@ func (c *GroupClient) DeleteOne(gr *Group) *GroupDeleteOne { } // DeleteOneID returns a delete builder for the given id. -func (c *GroupClient) DeleteOneID(id string) *GroupDeleteOne { +func (c *GroupClient) DeleteOneID(id int) *GroupDeleteOne { return &GroupDeleteOne{c.Delete().Where(group.ID(id))} } @@ -134,7 +134,7 @@ func (c *PetClient) UpdateOne(pe *Pet) *PetUpdateOne { } // UpdateOneID returns an update builder for the given id. -func (c *PetClient) UpdateOneID(id string) *PetUpdateOne { +func (c *PetClient) UpdateOneID(id int) *PetUpdateOne { return &PetUpdateOne{config: c.config, id: id} } @@ -149,7 +149,7 @@ func (c *PetClient) DeleteOne(pe *Pet) *PetDeleteOne { } // DeleteOneID returns a delete builder for the given id. -func (c *PetClient) DeleteOneID(id string) *PetDeleteOne { +func (c *PetClient) DeleteOneID(id int) *PetDeleteOne { return &PetDeleteOne{c.Delete().Where(pet.ID(id))} } @@ -184,7 +184,7 @@ func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { } // UpdateOneID returns an update builder for the given id. -func (c *UserClient) UpdateOneID(id string) *UserUpdateOne { +func (c *UserClient) UpdateOneID(id int) *UserUpdateOne { return &UserUpdateOne{config: c.config, id: id} } @@ -199,7 +199,7 @@ func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { } // DeleteOneID returns a delete builder for the given id. -func (c *UserClient) DeleteOneID(id string) *UserDeleteOne { +func (c *UserClient) DeleteOneID(id int) *UserDeleteOne { return &UserDeleteOne{c.Delete().Where(user.ID(id))} } diff --git a/entc/integration/migrate/entv2/ent.go b/entc/integration/migrate/entv2/ent.go index 8e9f84cf3..f36be7552 100644 --- a/entc/integration/migrate/entv2/ent.go +++ b/entc/integration/migrate/entv2/ent.go @@ -183,8 +183,8 @@ func rollback(tx dialect.Tx, err error) error { } // keys returns the keys/ids from the edge map. -func keys(m map[string]struct{}) []string { - s := make([]string, 0, len(m)) +func keys(m map[int]struct{}) []int { + s := make([]int, 0, len(m)) for id, _ := range m { s = append(s, id) } diff --git a/entc/integration/migrate/entv2/group.go b/entc/integration/migrate/entv2/group.go index 4af837038..d01275c72 100644 --- a/entc/integration/migrate/entv2/group.go +++ b/entc/integration/migrate/entv2/group.go @@ -5,7 +5,6 @@ package entv2 import ( "bytes" "fmt" - "strconv" "fbc/ent/dialect/sql" ) @@ -14,7 +13,7 @@ import ( type Group struct { config // ID of the ent. - ID string `json:"id,omitempty"` + ID int `json:"id,omitempty"` } // FromRows scans the sql response data into Group. @@ -28,7 +27,7 @@ func (gr *Group) FromRows(rows *sql.Rows) error { ); err != nil { return err } - gr.ID = strconv.Itoa(vgr.ID) + gr.ID = vgr.ID return nil } @@ -59,12 +58,6 @@ func (gr *Group) String() string { return buf.String() } -// id returns the int representation of the ID field. -func (gr *Group) id() int { - id, _ := strconv.Atoi(gr.ID) - return id -} - // Groups is a parsable slice of Group. type Groups []*Group diff --git a/entc/integration/migrate/entv2/group/where.go b/entc/integration/migrate/entv2/group/where.go index 2e229ec58..3b778433c 100644 --- a/entc/integration/migrate/entv2/group/where.go +++ b/entc/integration/migrate/entv2/group/where.go @@ -3,85 +3,76 @@ package group import ( - "strconv" - "fbc/ent/entc/integration/migrate/entv2/predicate" "fbc/ent/dialect/sql" ) // ID filters vertices based on their identifier. -func ID(id string) predicate.Group { +func ID(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id string) predicate.Group { +func IDEQ(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id string) predicate.Group { +func IDNEQ(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + s.Where(sql.NEQ(s.C(FieldID), id)) }, ) } // IDGT applies the GT predicate on the ID field. -func IDGT(id string) predicate.Group { +func IDGT(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + s.Where(sql.GT(s.C(FieldID), id)) }, ) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id string) predicate.Group { +func IDGTE(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + s.Where(sql.GTE(s.C(FieldID), id)) }, ) } // IDLT applies the LT predicate on the ID field. -func IDLT(id string) predicate.Group { +func IDLT(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + s.Where(sql.LT(s.C(FieldID), id)) }, ) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id string) predicate.Group { +func IDLTE(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + s.Where(sql.LTE(s.C(FieldID), id)) }, ) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...string) predicate.Group { +func IDIn(ids ...int) predicate.Group { return predicate.Group( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -92,7 +83,7 @@ func IDIn(ids ...string) predicate.Group { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.In(s.C(FieldID), v...)) }, @@ -100,7 +91,7 @@ func IDIn(ids ...string) predicate.Group { } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...string) predicate.Group { +func IDNotIn(ids ...int) predicate.Group { return predicate.Group( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -111,7 +102,7 @@ func IDNotIn(ids ...string) predicate.Group { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.NotIn(s.C(FieldID), v...)) }, diff --git a/entc/integration/migrate/entv2/group_create.go b/entc/integration/migrate/entv2/group_create.go index 5d8247705..f3243a418 100644 --- a/entc/integration/migrate/entv2/group_create.go +++ b/entc/integration/migrate/entv2/group_create.go @@ -5,7 +5,6 @@ package entv2 import ( "context" "errors" - "strconv" "fbc/ent/entc/integration/migrate/entv2/group" @@ -55,7 +54,7 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) { if err != nil { return nil, rollback(tx, err) } - gr.ID = strconv.FormatInt(id, 10) + gr.ID = int(id) if err := tx.Commit(); err != nil { return nil, err } diff --git a/entc/integration/migrate/entv2/group_query.go b/entc/integration/migrate/entv2/group_query.go index b7ed4bac2..c43219e73 100644 --- a/entc/integration/migrate/entv2/group_query.go +++ b/entc/integration/migrate/entv2/group_query.go @@ -52,12 +52,12 @@ func (gq *GroupQuery) Order(o ...Order) *GroupQuery { } // Get returns a Group entity by its id. -func (gq *GroupQuery) Get(ctx context.Context, id string) (*Group, error) { +func (gq *GroupQuery) Get(ctx context.Context, id int) (*Group, error) { return gq.Where(group.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. -func (gq *GroupQuery) GetX(ctx context.Context, id string) *Group { +func (gq *GroupQuery) GetX(ctx context.Context, id int) *Group { gr, err := gq.Get(ctx, id) if err != nil { panic(err) @@ -87,8 +87,8 @@ func (gq *GroupQuery) FirstX(ctx context.Context) *Group { } // FirstID returns the first Group id in the query. Returns *ErrNotFound when no id was found. -func (gq *GroupQuery) FirstID(ctx context.Context) (id string, err error) { - var ids []string +func (gq *GroupQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = gq.Limit(1).IDs(ctx); err != nil { return } @@ -100,7 +100,7 @@ func (gq *GroupQuery) FirstID(ctx context.Context) (id string, err error) { } // FirstXID is like FirstID, but panics if an error occurs. -func (gq *GroupQuery) FirstXID(ctx context.Context) string { +func (gq *GroupQuery) FirstXID(ctx context.Context) int { id, err := gq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -134,8 +134,8 @@ func (gq *GroupQuery) OnlyX(ctx context.Context) *Group { } // OnlyID returns the only Group id in the query, returns an error if not exactly one id was returned. -func (gq *GroupQuery) OnlyID(ctx context.Context) (id string, err error) { - var ids []string +func (gq *GroupQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = gq.Limit(2).IDs(ctx); err != nil { return } @@ -151,7 +151,7 @@ func (gq *GroupQuery) OnlyID(ctx context.Context) (id string, err error) { } // OnlyXID is like OnlyID, but panics if an error occurs. -func (gq *GroupQuery) OnlyXID(ctx context.Context) string { +func (gq *GroupQuery) OnlyXID(ctx context.Context) int { id, err := gq.OnlyID(ctx) if err != nil { panic(err) @@ -179,7 +179,7 @@ func (gq *GroupQuery) AllX(ctx context.Context) []*Group { } // IDs executes the query and returns a list of Group ids. -func (gq *GroupQuery) IDs(ctx context.Context) ([]string, error) { +func (gq *GroupQuery) IDs(ctx context.Context) ([]int, error) { switch gq.driver.Dialect() { case dialect.MySQL, dialect.SQLite: return gq.sqlIDs(ctx) @@ -189,7 +189,7 @@ func (gq *GroupQuery) IDs(ctx context.Context) ([]string, error) { } // IDsX is like IDs, but panics if an error occurs. -func (gq *GroupQuery) IDsX(ctx context.Context) []string { +func (gq *GroupQuery) IDsX(ctx context.Context) []int { ids, err := gq.IDs(ctx) if err != nil { panic(err) @@ -312,12 +312,12 @@ func (gq *GroupQuery) sqlExist(ctx context.Context) (bool, error) { return n > 0, nil } -func (gq *GroupQuery) sqlIDs(ctx context.Context) ([]string, error) { +func (gq *GroupQuery) sqlIDs(ctx context.Context) ([]int, error) { vs, err := gq.sqlAll(ctx) if err != nil { return nil, err } - var ids []string + var ids []int for _, v := range vs { ids = append(ids, v.ID) } diff --git a/entc/integration/migrate/entv2/group_update.go b/entc/integration/migrate/entv2/group_update.go index 4da8ce779..b24067df0 100644 --- a/entc/integration/migrate/entv2/group_update.go +++ b/entc/integration/migrate/entv2/group_update.go @@ -94,7 +94,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { // GroupUpdateOne is the builder for updating a single Group entity. type GroupUpdateOne struct { config - id string + id int } // Save executes the query and returns the updated entity. @@ -145,7 +145,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) { if err := gr.FromRows(rows); err != nil { return nil, fmt.Errorf("entv2: failed scanning row into Group: %v", err) } - id = gr.id() + id = gr.ID ids = append(ids, id) } switch n := len(ids); { diff --git a/entc/integration/migrate/entv2/pet.go b/entc/integration/migrate/entv2/pet.go index 2eb9666c6..56afc64ac 100644 --- a/entc/integration/migrate/entv2/pet.go +++ b/entc/integration/migrate/entv2/pet.go @@ -5,7 +5,6 @@ package entv2 import ( "bytes" "fmt" - "strconv" "fbc/ent/dialect/sql" ) @@ -14,7 +13,7 @@ import ( type Pet struct { config // ID of the ent. - ID string `json:"id,omitempty"` + ID int `json:"id,omitempty"` } // FromRows scans the sql response data into Pet. @@ -28,7 +27,7 @@ func (pe *Pet) FromRows(rows *sql.Rows) error { ); err != nil { return err } - pe.ID = strconv.Itoa(vpe.ID) + pe.ID = vpe.ID return nil } @@ -59,12 +58,6 @@ func (pe *Pet) String() string { return buf.String() } -// id returns the int representation of the ID field. -func (pe *Pet) id() int { - id, _ := strconv.Atoi(pe.ID) - return id -} - // Pets is a parsable slice of Pet. type Pets []*Pet diff --git a/entc/integration/migrate/entv2/pet/where.go b/entc/integration/migrate/entv2/pet/where.go index aa1a648eb..9994d6a75 100644 --- a/entc/integration/migrate/entv2/pet/where.go +++ b/entc/integration/migrate/entv2/pet/where.go @@ -3,85 +3,76 @@ package pet import ( - "strconv" - "fbc/ent/entc/integration/migrate/entv2/predicate" "fbc/ent/dialect/sql" ) // ID filters vertices based on their identifier. -func ID(id string) predicate.Pet { +func ID(id int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id string) predicate.Pet { +func IDEQ(id int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id string) predicate.Pet { +func IDNEQ(id int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + s.Where(sql.NEQ(s.C(FieldID), id)) }, ) } // IDGT applies the GT predicate on the ID field. -func IDGT(id string) predicate.Pet { +func IDGT(id int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + s.Where(sql.GT(s.C(FieldID), id)) }, ) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id string) predicate.Pet { +func IDGTE(id int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + s.Where(sql.GTE(s.C(FieldID), id)) }, ) } // IDLT applies the LT predicate on the ID field. -func IDLT(id string) predicate.Pet { +func IDLT(id int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + s.Where(sql.LT(s.C(FieldID), id)) }, ) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id string) predicate.Pet { +func IDLTE(id int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + s.Where(sql.LTE(s.C(FieldID), id)) }, ) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...string) predicate.Pet { +func IDIn(ids ...int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -92,7 +83,7 @@ func IDIn(ids ...string) predicate.Pet { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.In(s.C(FieldID), v...)) }, @@ -100,7 +91,7 @@ func IDIn(ids ...string) predicate.Pet { } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...string) predicate.Pet { +func IDNotIn(ids ...int) predicate.Pet { return predicate.Pet( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -111,7 +102,7 @@ func IDNotIn(ids ...string) predicate.Pet { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.NotIn(s.C(FieldID), v...)) }, diff --git a/entc/integration/migrate/entv2/pet_create.go b/entc/integration/migrate/entv2/pet_create.go index 96fc85923..70ac6a194 100644 --- a/entc/integration/migrate/entv2/pet_create.go +++ b/entc/integration/migrate/entv2/pet_create.go @@ -5,7 +5,6 @@ package entv2 import ( "context" "errors" - "strconv" "fbc/ent/entc/integration/migrate/entv2/pet" @@ -55,7 +54,7 @@ func (pc *PetCreate) sqlSave(ctx context.Context) (*Pet, error) { if err != nil { return nil, rollback(tx, err) } - pe.ID = strconv.FormatInt(id, 10) + pe.ID = int(id) if err := tx.Commit(); err != nil { return nil, err } diff --git a/entc/integration/migrate/entv2/pet_query.go b/entc/integration/migrate/entv2/pet_query.go index c4076cd98..ea0d4d877 100644 --- a/entc/integration/migrate/entv2/pet_query.go +++ b/entc/integration/migrate/entv2/pet_query.go @@ -52,12 +52,12 @@ func (pq *PetQuery) Order(o ...Order) *PetQuery { } // Get returns a Pet entity by its id. -func (pq *PetQuery) Get(ctx context.Context, id string) (*Pet, error) { +func (pq *PetQuery) Get(ctx context.Context, id int) (*Pet, error) { return pq.Where(pet.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. -func (pq *PetQuery) GetX(ctx context.Context, id string) *Pet { +func (pq *PetQuery) GetX(ctx context.Context, id int) *Pet { pe, err := pq.Get(ctx, id) if err != nil { panic(err) @@ -87,8 +87,8 @@ func (pq *PetQuery) FirstX(ctx context.Context) *Pet { } // FirstID returns the first Pet id in the query. Returns *ErrNotFound when no id was found. -func (pq *PetQuery) FirstID(ctx context.Context) (id string, err error) { - var ids []string +func (pq *PetQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = pq.Limit(1).IDs(ctx); err != nil { return } @@ -100,7 +100,7 @@ func (pq *PetQuery) FirstID(ctx context.Context) (id string, err error) { } // FirstXID is like FirstID, but panics if an error occurs. -func (pq *PetQuery) FirstXID(ctx context.Context) string { +func (pq *PetQuery) FirstXID(ctx context.Context) int { id, err := pq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -134,8 +134,8 @@ func (pq *PetQuery) OnlyX(ctx context.Context) *Pet { } // OnlyID returns the only Pet id in the query, returns an error if not exactly one id was returned. -func (pq *PetQuery) OnlyID(ctx context.Context) (id string, err error) { - var ids []string +func (pq *PetQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = pq.Limit(2).IDs(ctx); err != nil { return } @@ -151,7 +151,7 @@ func (pq *PetQuery) OnlyID(ctx context.Context) (id string, err error) { } // OnlyXID is like OnlyID, but panics if an error occurs. -func (pq *PetQuery) OnlyXID(ctx context.Context) string { +func (pq *PetQuery) OnlyXID(ctx context.Context) int { id, err := pq.OnlyID(ctx) if err != nil { panic(err) @@ -179,7 +179,7 @@ func (pq *PetQuery) AllX(ctx context.Context) []*Pet { } // IDs executes the query and returns a list of Pet ids. -func (pq *PetQuery) IDs(ctx context.Context) ([]string, error) { +func (pq *PetQuery) IDs(ctx context.Context) ([]int, error) { switch pq.driver.Dialect() { case dialect.MySQL, dialect.SQLite: return pq.sqlIDs(ctx) @@ -189,7 +189,7 @@ func (pq *PetQuery) IDs(ctx context.Context) ([]string, error) { } // IDsX is like IDs, but panics if an error occurs. -func (pq *PetQuery) IDsX(ctx context.Context) []string { +func (pq *PetQuery) IDsX(ctx context.Context) []int { ids, err := pq.IDs(ctx) if err != nil { panic(err) @@ -312,12 +312,12 @@ func (pq *PetQuery) sqlExist(ctx context.Context) (bool, error) { return n > 0, nil } -func (pq *PetQuery) sqlIDs(ctx context.Context) ([]string, error) { +func (pq *PetQuery) sqlIDs(ctx context.Context) ([]int, error) { vs, err := pq.sqlAll(ctx) if err != nil { return nil, err } - var ids []string + var ids []int for _, v := range vs { ids = append(ids, v.ID) } diff --git a/entc/integration/migrate/entv2/pet_update.go b/entc/integration/migrate/entv2/pet_update.go index f539741eb..68a7995c4 100644 --- a/entc/integration/migrate/entv2/pet_update.go +++ b/entc/integration/migrate/entv2/pet_update.go @@ -94,7 +94,7 @@ 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 string + id int } // Save executes the query and returns the updated entity. @@ -145,7 +145,7 @@ func (puo *PetUpdateOne) sqlSave(ctx context.Context) (pe *Pet, err error) { if err := pe.FromRows(rows); err != nil { return nil, fmt.Errorf("entv2: failed scanning row into Pet: %v", err) } - id = pe.id() + id = pe.ID ids = append(ids, id) } switch n := len(ids); { diff --git a/entc/integration/migrate/entv2/user.go b/entc/integration/migrate/entv2/user.go index 541cac1e3..413701d04 100644 --- a/entc/integration/migrate/entv2/user.go +++ b/entc/integration/migrate/entv2/user.go @@ -5,7 +5,6 @@ package entv2 import ( "bytes" "fmt" - "strconv" "fbc/ent/dialect/sql" ) @@ -14,7 +13,7 @@ import ( type User struct { config // ID of the ent. - ID string `json:"id,omitempty"` + ID int `json:"id,omitempty"` // Age holds the value of the "age" field. Age int `json:"age,omitempty"` // Name holds the value of the "name" field. @@ -44,7 +43,7 @@ func (u *User) FromRows(rows *sql.Rows) error { ); err != nil { return err } - u.ID = strconv.Itoa(vu.ID) + u.ID = vu.ID u.Age = vu.Age u.Name = vu.Name u.Phone = vu.Phone @@ -83,12 +82,6 @@ func (u *User) String() string { return buf.String() } -// id returns the int representation of the ID field. -func (u *User) id() int { - id, _ := strconv.Atoi(u.ID) - return id -} - // Users is a parsable slice of User. type Users []*User diff --git a/entc/integration/migrate/entv2/user/where.go b/entc/integration/migrate/entv2/user/where.go index 42363a626..833cc6618 100644 --- a/entc/integration/migrate/entv2/user/where.go +++ b/entc/integration/migrate/entv2/user/where.go @@ -3,85 +3,76 @@ package user import ( - "strconv" - "fbc/ent/entc/integration/migrate/entv2/predicate" "fbc/ent/dialect/sql" ) // ID filters vertices based on their identifier. -func ID(id string) predicate.User { +func ID(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id string) predicate.User { +func IDEQ(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.EQ(s.C(FieldID), v)) + s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id string) predicate.User { +func IDNEQ(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.NEQ(s.C(FieldID), v)) + s.Where(sql.NEQ(s.C(FieldID), id)) }, ) } // IDGT applies the GT predicate on the ID field. -func IDGT(id string) predicate.User { +func IDGT(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GT(s.C(FieldID), v)) + s.Where(sql.GT(s.C(FieldID), id)) }, ) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id string) predicate.User { +func IDGTE(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.GTE(s.C(FieldID), v)) + s.Where(sql.GTE(s.C(FieldID), id)) }, ) } // IDLT applies the LT predicate on the ID field. -func IDLT(id string) predicate.User { +func IDLT(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LT(s.C(FieldID), v)) + s.Where(sql.LT(s.C(FieldID), id)) }, ) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id string) predicate.User { +func IDLTE(id int) predicate.User { return predicate.User( func(s *sql.Selector) { - v, _ := strconv.Atoi(id) - s.Where(sql.LTE(s.C(FieldID), v)) + s.Where(sql.LTE(s.C(FieldID), id)) }, ) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...string) predicate.User { +func IDIn(ids ...int) predicate.User { return predicate.User( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -92,7 +83,7 @@ func IDIn(ids ...string) predicate.User { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.In(s.C(FieldID), v...)) }, @@ -100,7 +91,7 @@ func IDIn(ids ...string) predicate.User { } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...string) predicate.User { +func IDNotIn(ids ...int) predicate.User { return predicate.User( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -111,7 +102,7 @@ func IDNotIn(ids ...string) predicate.User { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.NotIn(s.C(FieldID), v...)) }, diff --git a/entc/integration/migrate/entv2/user_create.go b/entc/integration/migrate/entv2/user_create.go index fc76ce250..f8135c0d3 100644 --- a/entc/integration/migrate/entv2/user_create.go +++ b/entc/integration/migrate/entv2/user_create.go @@ -5,7 +5,6 @@ package entv2 import ( "context" "errors" - "strconv" "fbc/ent/entc/integration/migrate/entv2/user" @@ -112,7 +111,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { if err != nil { return nil, rollback(tx, err) } - u.ID = strconv.FormatInt(id, 10) + u.ID = int(id) if err := tx.Commit(); err != nil { return nil, err } diff --git a/entc/integration/migrate/entv2/user_query.go b/entc/integration/migrate/entv2/user_query.go index c9e127edc..331623cac 100644 --- a/entc/integration/migrate/entv2/user_query.go +++ b/entc/integration/migrate/entv2/user_query.go @@ -52,12 +52,12 @@ func (uq *UserQuery) Order(o ...Order) *UserQuery { } // Get returns a User entity by its id. -func (uq *UserQuery) Get(ctx context.Context, id string) (*User, error) { +func (uq *UserQuery) Get(ctx context.Context, id int) (*User, error) { return uq.Where(user.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. -func (uq *UserQuery) GetX(ctx context.Context, id string) *User { +func (uq *UserQuery) GetX(ctx context.Context, id int) *User { u, err := uq.Get(ctx, id) if err != nil { panic(err) @@ -87,8 +87,8 @@ func (uq *UserQuery) FirstX(ctx context.Context) *User { } // FirstID returns the first User id in the query. Returns *ErrNotFound when no id was found. -func (uq *UserQuery) FirstID(ctx context.Context) (id string, err error) { - var ids []string +func (uq *UserQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = uq.Limit(1).IDs(ctx); err != nil { return } @@ -100,7 +100,7 @@ func (uq *UserQuery) FirstID(ctx context.Context) (id string, err error) { } // FirstXID is like FirstID, but panics if an error occurs. -func (uq *UserQuery) FirstXID(ctx context.Context) string { +func (uq *UserQuery) FirstXID(ctx context.Context) int { id, err := uq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -134,8 +134,8 @@ func (uq *UserQuery) OnlyX(ctx context.Context) *User { } // OnlyID returns the only User id in the query, returns an error if not exactly one id was returned. -func (uq *UserQuery) OnlyID(ctx context.Context) (id string, err error) { - var ids []string +func (uq *UserQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = uq.Limit(2).IDs(ctx); err != nil { return } @@ -151,7 +151,7 @@ func (uq *UserQuery) OnlyID(ctx context.Context) (id string, err error) { } // OnlyXID is like OnlyID, but panics if an error occurs. -func (uq *UserQuery) OnlyXID(ctx context.Context) string { +func (uq *UserQuery) OnlyXID(ctx context.Context) int { id, err := uq.OnlyID(ctx) if err != nil { panic(err) @@ -179,7 +179,7 @@ func (uq *UserQuery) AllX(ctx context.Context) []*User { } // IDs executes the query and returns a list of User ids. -func (uq *UserQuery) IDs(ctx context.Context) ([]string, error) { +func (uq *UserQuery) IDs(ctx context.Context) ([]int, error) { switch uq.driver.Dialect() { case dialect.MySQL, dialect.SQLite: return uq.sqlIDs(ctx) @@ -189,7 +189,7 @@ func (uq *UserQuery) IDs(ctx context.Context) ([]string, error) { } // IDsX is like IDs, but panics if an error occurs. -func (uq *UserQuery) IDsX(ctx context.Context) []string { +func (uq *UserQuery) IDsX(ctx context.Context) []int { ids, err := uq.IDs(ctx) if err != nil { panic(err) @@ -325,12 +325,12 @@ func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) { return n > 0, nil } -func (uq *UserQuery) sqlIDs(ctx context.Context) ([]string, error) { +func (uq *UserQuery) sqlIDs(ctx context.Context) ([]int, error) { vs, err := uq.sqlAll(ctx) if err != nil { return nil, err } - var ids []string + var ids []int for _, v := range vs { ids = append(ids, v.ID) } diff --git a/entc/integration/migrate/entv2/user_update.go b/entc/integration/migrate/entv2/user_update.go index 8e6b63eb6..511373535 100644 --- a/entc/integration/migrate/entv2/user_update.go +++ b/entc/integration/migrate/entv2/user_update.go @@ -149,7 +149,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { // UserUpdateOne is the builder for updating a single User entity. type UserUpdateOne struct { config - id string + id int age *int name *string phone *string @@ -228,7 +228,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) { if err := u.FromRows(rows); err != nil { return nil, fmt.Errorf("entv2: failed scanning row into User: %v", err) } - id = u.id() + id = u.ID ids = append(ids, id) } switch n := len(ids); { diff --git a/entc/integration/migrate/migrate_test.go b/entc/integration/migrate/migrate_test.go index e6d982e71..8340cc3e2 100644 --- a/entc/integration/migrate/migrate_test.go +++ b/entc/integration/migrate/migrate_test.go @@ -2,7 +2,6 @@ package migrate import ( "context" - "strconv" "testing" "fbc/ent/dialect/sql" @@ -82,8 +81,6 @@ func SanityV2(t *testing.T, client *entv2.Client) { require.NoError(t, err, "name is not limited to 10 chars") } -func idRange(t *testing.T, s string, l, h int) { - id, err := strconv.Atoi(s) - require.NoError(t, err) - require.Truef(t, id > l && id < h, "id %s should be between %d to %d", s, l, h) +func idRange(t *testing.T, id, l, h int) { + require.Truef(t, id > l && id < h, "id %s should be between %d to %d", id, l, h) }