diff --git a/cmd/entc/packages.go b/cmd/entc/packages.go index d4be5487d..6c1da1b40 100644 --- a/cmd/entc/packages.go +++ b/cmd/entc/packages.go @@ -29,8 +29,8 @@ func PkgPath(config *packages.Config, target string) (string, error) { parts = append(parts, filepath.Base(pathCheck)) pathCheck = filepath.Dir(pathCheck) } - // Try maximum 2 directories above the given target - // to find the root packages or module. + // Try maximum 2 directories above the given + // target to find the root package or module. for i := 0; i < 2; i++ { pkgs, err := packages.Load(config, pathCheck) if err != nil { diff --git a/entc/gen/func.go b/entc/gen/func.go index bea0b7d6c..77f476a09 100644 --- a/entc/gen/func.go +++ b/entc/gen/func.go @@ -130,7 +130,7 @@ func snake(s string) string { var b strings.Builder for i := 0; i < len(s); i++ { r := rune(s[i]) - // put '_' if it is not a start or end of a word, current letter is an uppercase letter, + // Put '_' if it is not a start or end of a word, current letter is an uppercase letter, // and previous letter is a lowercase letter (cases like: "UserInfo"), or next letter is // also a lowercase letter and previous letter is not "_". if i > 0 && i < len(s)-1 && unicode.IsUpper(r) && diff --git a/entc/gen/graph.go b/entc/gen/graph.go index 436a04cea..44829a67f 100644 --- a/entc/gen/graph.go +++ b/entc/gen/graph.go @@ -112,7 +112,7 @@ func (g *Graph) Gen() (err error) { } // We can't run "imports" on files when the state is not completed. // Because, "goimports" will drop undefined package. Therefore, it's - // suspended to end of the writing. + // suspended to the end of the writing. return formatFiles(written) } @@ -138,7 +138,7 @@ func (g *Graph) addEdges(schema *load.Schema) { typ, ok := g.typ(e.Type) expect(ok, "type %q does not exist for edge", e.Type) switch { - // assoc only. + // Assoc only. case !e.Inverse: t.Edges = append(t.Edges, &Edge{ Type: typ, @@ -148,7 +148,7 @@ func (g *Graph) addEdges(schema *load.Schema) { Optional: !e.Required, StructTag: e.Tag, }) - // inverse only. + // Inverse only. case e.Inverse && e.Ref == nil: expect(e.RefName != "", "missing reference name for inverse edge: %s.%s", t.Name, e.Name) t.Edges = append(t.Edges, &Edge{ @@ -160,7 +160,7 @@ func (g *Graph) addEdges(schema *load.Schema) { Optional: !e.Required, StructTag: e.Tag, }) - // inverse and assoc. + // Inverse and assoc. case e.Inverse: ref := e.Ref expect(e.RefName == "", "reference name is derived from the assoc name: %s.%s <-> %s.%s", t.Name, ref.Name, t.Name, e.Name) @@ -296,7 +296,7 @@ func (g *Graph) Tables() (all []*schema.Table) { all = append(all, table) } for _, n := range g.Nodes { - // foreign key + reference OR join table. + // Foreign key + reference OR join table. for _, e := range n.Edges { if e.IsInverse() { continue @@ -360,7 +360,7 @@ func (g *Graph) Tables() (all []*schema.Table) { } } } - // append indexes to tables after all columns were added (including relation columns). + // Append indexes to tables after all columns were added (including relation columns). for _, n := range g.Nodes { table := tables[n.Table()] for _, idx := range n.Indexes { @@ -394,8 +394,8 @@ func (g *Graph) templates() (*template.Template, []GraphTemplate) { external := make([]GraphTemplate, 0) for _, tmpl := range g.Template.Templates() { name := tmpl.Name() - // check that is not defined in the default templates - // it's not the root. + // Check that is not defined in the default templates + // if it's not the root. if templates.Lookup(name) == nil && !parse.IsEmptyTree(tmpl.Root) { external = append(external, GraphTemplate{ Name: name, diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index 264805366..048d90e38 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -761,7 +761,7 @@ func templateDialectSqlPredicateTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlQueryTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3a\x5d\x6f\xdb\x48\x92\xcf\xd4\xaf\xa8\x21\x7c\x03\xd1\x90\x69\x3b\x77\x38\xe0\x14\xf8\x00\x6f\x1c\x03\x42\x66\x32\xd9\x71\x66\xe6\xc1\x10\x66\x68\xb2\x28\x37\x44\x35\x15\xb2\xe5\x38\x50\xf8\xdf\x17\x55\xfd\xc1\xa6\x48\xc9\x4e\xe6\x63\x77\x81\x7d\x48\x2c\x75\x57\x57\x55\xd7\x77\x55\x6b\xbb\x3d\x3d\x1e\xbd\x2a\xd7\x9f\x2a\xb1\xb8\x57\xf0\xe2\xec\xfc\xff\x4e\xd6\x15\xd6\x28\x15\x5c\x27\x29\xde\x95\xe5\x12\x66\x32\x8d\xe1\xb2\x28\x80\x81\x6a\xa0\xfd\xea\x01\xb3\x78\xf4\xfe\x5e\xd4\x50\x97\x9b\x2a\x45\x48\xcb\x0c\x41\xd4\x50\x88\x14\x65\x8d\x19\x6c\x64\x86\x15\xa8\x7b\x84\xcb\x75\x92\xde\x23\xbc\x88\xcf\xec\x2e\xe4\xe5\x46\x66\x23\x21\x79\xff\xbb\xd9\xab\xd7\x6f\x6f\x5e\x43\x2e\x0a\x04\xb3\x56\x95\xa5\x82\x4c\x54\x98\xaa\xb2\xfa\x04\x65\x0e\xca\x23\xa6\x2a\xc4\x78\x74\x7c\xda\x34\xa3\x11\xdd\x01\x2e\xb3\x4c\x28\x51\xca\xa4\x80\x5c\x60\x91\xd5\x90\x97\x9a\xf8\xdd\x46\x14\x19\x56\x31\x30\xf4\x76\x0b\x19\xe6\x42\x22\x84\x99\x48\x0a\x4c\xd5\x69\xfd\xa1\x38\xfd\xb0\xc1\xea\xd3\xa9\x3e\x19\x42\xd3\x8c\x82\xed\xf6\x04\x3e\x0a\x75\x0f\x47\xf1\x75\x59\xa1\x58\xc8\x37\xf8\xa9\xe6\xad\x80\xd6\xaf\xdf\xd4\x70\x57\x96\x85\x86\x44\x99\x01\x63\x77\x1f\x0f\x52\x0a\x35\x30\x1c\xad\x97\x0b\x98\x5e\xc0\x51\x7c\x93\x96\x6b\x8c\xdf\x25\xe9\x32\x59\xa0\xdd\x35\xac\x13\xc4\x3a\xa9\xd3\xa4\x70\x80\x7f\x33\x3b\x06\xb0\xc2\x14\xc5\x83\x86\x74\x9f\xdd\x71\xe2\x26\xdf\xc8\x14\xc6\x1d\xd8\xa6\x81\x63\x9f\x4a\xd3\x44\x50\x7f\x28\x2e\x8b\x62\x9c\xaa\x47\x48\x4b\xa9\xf0\x51\xc5\xaf\xf4\xdf\x08\xc6\xb7\x73\x86\x8f\xdf\x26\x2b\x62\x71\x02\x58\x55\x65\x15\xc1\x76\x14\x3c\x24\x15\x8c\x47\x41\x20\xcb\x0c\x6b\xb8\x80\x1d\xd0\x2d\x49\xed\x90\x44\x9d\x48\x2f\x60\x87\xc7\xd8\xec\x18\x04\x46\xba\x41\xf0\x6b\xbd\xc6\x74\x00\x9c\xe5\x7b\xb3\xc6\x74\x1c\x75\x69\xbe\xce\x16\x68\xa9\x15\x65\x92\x61\xf6\xfe\xd3\x5a\x33\xbb\xdd\x42\x81\x12\x62\x68\x9a\x39\xe9\x74\x4b\x30\x7c\xb6\x4a\xe4\x02\xe1\x08\x49\xb0\xb1\x39\x4c\x3b\x7d\x16\xb7\x5b\xa7\x23\xb4\xd7\x86\x6f\x2e\x40\x8a\x62\xe2\xd0\x39\xee\x83\x66\xe7\x3e\xd1\x61\x8b\xeb\x6c\xbe\xf1\xaf\x12\x88\x9c\x64\x60\x18\x15\x13\x8f\xd9\xed\x16\x44\x0e\x0b\x05\x47\x02\xce\x88\x9d\xcf\x9f\x09\x54\x93\xfc\xc2\x3b\xb8\x73\xa0\x85\xe3\x29\x4c\x55\x1b\xe4\x35\xc7\x68\x7b\x4d\x91\x83\x05\xd4\xe7\x58\x6d\xf1\xdb\x32\xc3\xf8\x55\x59\x6c\x56\x92\x30\x24\xeb\x35\xca\x6c\xdc\xdf\x9b\xb0\x7a\x3d\xb7\xf0\x25\x13\xc7\x71\x64\x44\xe9\x13\xd5\x58\x6e\xd2\x44\xfe\x9c\x14\x1b\x56\x30\x19\xff\x38\x82\xdb\xb9\x90\x0a\xab\x3c\x49\x71\xab\xef\x41\xe6\x4a\xd2\xfa\xb6\x63\xac\x69\x29\x73\xb1\x98\xf6\x4c\x4b\xaf\x37\x9e\x99\x1b\xc6\xf9\xeb\x04\xe8\x0f\x71\xf4\xa0\xe9\x4e\x2f\x78\x25\xae\x1d\x2b\xbb\x26\xd9\x57\x73\x4f\x5e\x0f\xf6\x0e\x86\x94\xfe\xae\x69\xc5\xf9\xd2\xe2\xf5\x64\xd1\xd5\x40\x85\x6a\x53\x49\xd0\xc7\x46\x81\x93\xcf\x65\x5d\x8b\x85\xb4\xb2\x31\x54\xe2\x38\xf6\x24\x14\x69\xff\x66\x46\x44\x4e\x1e\xa2\x2f\x1a\xc1\xc5\x05\x9c\x69\xfe\x0c\xfa\x7c\xa5\xe2\xd7\x04\x9c\x8f\x43\x1b\xd6\x9a\x66\x0a\x86\x4a\x9a\x14\x05\x66\x7c\xb3\x72\xa3\xf8\xab\x90\x0b\x68\x75\x14\x12\xf3\x8d\xa7\x10\x26\x74\xdb\x92\x3c\x39\x9f\xef\xf7\x66\x96\x05\x2f\xc4\x5d\xc7\xf6\xbe\xed\x91\x0b\x1f\x4d\x98\x4b\x23\x4a\x2d\x0a\x2d\xcf\x66\x44\x17\xc7\x8a\xe3\x6a\xfd\xa1\x58\x54\xc9\xfa\x3e\xfe\x3b\x45\x18\xb2\xd2\x9a\xe2\xe4\xa4\x67\x26\x59\x45\x9f\x26\xc0\x82\x8e\x5e\xf2\x79\xed\x44\x2c\x33\x4b\x59\x14\x1c\x40\x2d\x95\x21\xf1\x7a\x4c\x92\xca\x45\x31\xb2\xc6\xee\xc7\xa5\x8e\x30\x9c\x88\xf0\x51\xd1\x65\x8f\x20\xfc\x11\xd3\xd0\xe3\x30\x24\xe8\x90\xce\xda\xc8\x02\x0a\x57\xeb\x22\x51\x83\x39\x11\x93\x05\x56\x24\x48\x21\x17\xa1\x8d\x81\xbe\x28\xfd\xcf\x7d\x86\xbf\x28\xf5\xbc\x2a\x37\x52\xed\x49\x3e\x42\x2a\x3f\xe1\xe8\xf0\x3f\x7d\x22\xfe\x1b\x7e\x9c\xea\x98\xc0\xb3\x55\xf7\x65\xcc\xbf\x7e\x14\xf5\x3e\xe6\x29\xa9\xf8\xdc\xcb\x89\xb5\xaa\x5d\x0e\x7c\x29\x44\xce\xfc\xfa\xe6\x93\x27\x45\x8d\x93\xbd\x8e\x97\xde\x63\xba\x04\x24\x96\x50\xa6\x38\x85\xff\x7a\x08\x99\xa6\xb6\x6a\xab\x27\xf8\x7f\x38\xfb\x52\x3d\x79\x02\x86\xe3\xae\x53\xd0\x6a\x47\x39\xdf\xf6\xf7\xe9\x0e\xa4\x81\xa9\xb7\x49\xdf\xed\x5e\xf0\x3e\xb9\x2b\x70\xda\x0b\xfc\xbc\xcc\x99\xd4\xe4\x86\x3e\x88\x4d\x1a\x04\x34\xbb\xf2\x09\x5c\x53\x61\xe7\x28\x04\x14\x11\xa6\xba\x4e\x8c\x19\xc9\xec\x2a\xa6\x35\xd2\x58\xad\x6c\x79\xc3\xa0\x1a\x67\x9f\x96\x3d\xc6\x27\x12\xa9\xec\x01\xfe\x9f\xff\xbb\xae\xca\x55\x3f\x87\xd4\x1f\xb8\x1c\xf8\x49\x8a\x0f\x1b\x9c\x72\xee\x9c\xd8\x10\xb0\xae\x87\x2c\x62\x5d\x61\x26\xd2\x44\x61\xfd\x92\x83\xc4\xba\x8e\x48\x6d\x6c\x0c\x3a\x96\xbf\xb3\x10\x36\x9c\xd7\x58\x70\xd9\xcc\xfa\x89\x6f\xcc\xb7\x48\x87\x6c\xaa\x8b\x05\x17\x8a\x1c\x43\xd6\x36\xd3\xac\xeb\x5b\x31\x77\x47\x5d\x36\x69\x5c\x80\x12\x2b\xa1\x86\x18\xe4\x8d\x97\x66\xdf\xb3\x54\xcd\xdc\x77\xbc\x7c\x01\xc7\xbc\x6f\x91\x95\x79\x5e\xe3\x20\x36\xbd\xf3\xd2\x42\xf4\xf0\xfd\xa0\xd7\x2f\xe0\x58\x43\x1c\x16\x5e\x59\x65\x58\xed\x93\xdb\x0f\xb4\xf9\xe7\xc9\xcc\x38\x19\xd3\xfa\xb2\x50\xc2\xce\x62\xdc\xcb\xb1\x42\x24\xbd\x86\x80\xb6\xae\x74\xb4\xde\xc5\x69\xc2\x98\xdb\x8e\xa2\x51\xa0\xce\xe9\x90\xed\x85\xd8\x99\xc6\x83\x2e\x16\x8d\x02\x27\x0a\xef\x84\xe6\x62\xac\xce\xad\x97\xf5\x4e\x9b\x75\xca\x9c\xfc\x8f\xec\x7f\xac\xce\x75\x10\x1b\x70\x03\x5f\xb5\x8e\xe2\x60\x40\xf4\x00\x2c\x1f\xee\xfb\x33\xb9\x61\x85\x90\x16\x7f\x9d\xc0\xba\x55\xe4\x7e\x5f\x63\xb6\xd6\xbe\x6a\x9f\x85\x80\xed\x6d\xf0\xec\x57\x1a\xfd\xe9\xa9\x71\x2c\x51\xc3\x2a\x91\x59\xc2\xdd\x30\x31\x62\x60\xd3\x22\xd9\xd4\x18\xc3\x2f\x08\xb5\x4a\x2a\xa5\xcf\x70\x09\x90\x61\x9e\x6c\x0a\xa5\x8b\xbf\x09\x24\x32\x83\xf2\x01\xab\x4a\x50\xa3\xae\xe0\x0e\x8b\xf2\x23\x75\x08\x12\x31\xa3\x6e\xde\x13\xb3\xf6\xb2\xb1\xf1\xb1\x48\x7b\xf1\x78\x95\xa8\xfb\xf8\xfb\xe4\x71\x26\xd5\x7f\xbf\x88\xbe\x3a\x30\x38\x2a\x1a\xab\x8e\x0c\x9d\xc4\x64\x21\x46\xdc\xde\xb6\x1d\xf5\xe9\xb1\x4e\x3f\xa7\xeb\x44\xdf\x4f\x48\xac\xb9\xcb\xe7\x65\x58\xa0\xc4\x2a\x51\xa2\x94\x2c\x22\x86\x2a\x73\x48\x60\x21\x1e\x50\x02\x66\x0b\x7c\xce\x1c\x80\xce\xb5\x53\x80\x23\xc9\x55\x16\xf7\x3e\xc4\x01\x91\xe3\x3a\xf5\xa3\x11\xb9\xc7\x40\x5e\x95\x2b\x43\x41\x9f\x45\xbf\xbd\xa7\xca\xab\x83\x86\x18\x22\x34\xa4\x01\x50\x25\xf3\xbf\xa8\x28\x92\xd3\x2e\xb3\xaf\xca\x0e\x3e\xbf\xd3\xb7\x68\x7f\x6c\x65\x3e\x0a\x6a\x85\xeb\x4e\xb9\xfa\x16\x3f\xde\x28\x5c\x53\x77\xde\xe6\x43\xf2\x4d\x52\x97\xec\xa7\x58\xe8\xad\xeb\x85\x9d\x64\x37\xe4\xa8\x26\x6e\x45\x13\x9f\xd6\xfb\x92\x29\xa1\xce\xb0\xc3\xe4\xfa\x9b\xde\x6a\x97\x70\x17\x39\x49\x74\xec\xbe\xe9\x43\x3f\x62\xc1\x07\x1d\x97\x18\xcf\xea\x99\x7c\xc0\xaa\x6e\xd7\x7a\x17\x44\xcd\xcf\x6e\x3e\x27\xa1\x8b\x9c\xb6\xbf\x7f\xf1\x3d\x9c\x98\x9e\x7b\x0f\x86\x77\x6f\xbc\xe3\x71\x1c\xbb\x7e\xb8\xa8\xf1\xa9\xb3\x3a\x60\x79\xe7\xfd\x66\x5a\x9f\xa5\xab\x47\xa3\x80\x2d\x8d\x23\xa8\xa7\xe5\x1b\x54\x6f\x51\x2c\xee\xef\xca\xaa\x7e\x32\x1f\x4c\x80\xac\x24\xda\xe3\x5b\x64\xc3\x4f\xfb\x56\xa2\xdd\xc9\xb3\x7b\xe7\x66\xdc\x54\x3d\x67\xdc\x56\x95\xab\x7f\x47\x37\x63\x6d\x88\x6c\x28\xe4\x59\x73\x61\x77\x99\xd5\x37\xaa\xa2\x46\xb7\x69\x44\x36\x8e\x48\xda\x05\x9b\xe0\xec\xaa\x95\xfc\x5f\xe7\xb0\x22\xfb\x8f\x63\xfe\xf5\x8e\xf9\x3b\xbd\xf2\x80\xfb\x74\x3b\xf3\x83\xae\x70\xd8\xaa\x19\x40\xe4\xc6\xb7\x06\xac\x7a\xdf\x6c\xf0\xa5\x39\xe2\xe5\xf6\xae\x5a\xb4\xb0\xf2\x25\xd7\xe6\xab\x64\x89\xe3\xdb\xb9\xb9\xf6\xcf\xba\x28\x39\x9b\x78\x93\x0f\x2e\xa0\x45\xd6\x42\xaf\x92\xf5\xad\xdf\xa0\x41\xd3\xec\xce\xa0\x77\x4e\x9b\x12\xcd\xce\x91\x74\x95\xa6\xc7\x75\xba\x64\x17\x59\x7d\xcb\x01\x6a\x76\x35\x07\x3d\x68\xe2\x75\x62\xd2\x4d\xd9\xf2\xa5\x1d\xb1\xcd\xae\x5c\x55\xef\x86\xdc\x41\x40\x01\x85\xf8\xbc\x9d\x77\xdd\xc1\xf0\xe8\x60\x08\x65\xe7\x22\x3d\xd0\xf9\xce\xa4\x9c\xa9\xf1\x7f\x03\x4d\x34\x69\xb3\xd3\x48\x07\x01\x2d\x4d\x77\x40\xda\xdd\xc0\x78\xd7\x74\xc8\xdd\x34\xc4\x9e\x76\xfb\x80\xe7\x1d\xe8\xc0\x07\xbc\x4d\x1f\x31\x7f\x5c\xa7\x3a\x35\x4d\xd7\x60\xb7\x15\x04\x75\xfc\xcb\x3d\x56\x1c\x40\xe2\x99\x9d\xcc\x3d\x83\xd8\xad\x1e\x79\xef\xdc\xf4\xbc\x8d\xbc\x67\xce\xb9\xe6\x13\xc8\x97\xdc\x1f\x44\x3e\x87\x84\xb4\xdc\x70\x39\x1b\x12\xf5\xb7\x9b\xa2\x98\x49\xf5\xbf\xff\x13\xba\x81\x3a\x5b\xe3\x4f\x35\x56\x57\xec\x9a\x76\x98\x4e\xa7\x2e\xf4\x26\x1d\x32\xfa\xf5\x02\xbd\xc1\x2e\xe4\x41\xe4\xad\x85\xf4\x49\x08\x49\x14\x5a\x88\xbd\x74\xda\xc9\xea\xd4\x0d\xbf\x5f\xf8\xd3\x6f\x23\x67\x53\x6e\xef\xec\x7d\x6b\xaf\xd3\x34\xdb\x66\xa2\x87\xe3\x42\xf2\xb7\xc6\x97\x95\x9e\xee\x1a\x0a\xe5\x46\x4d\x40\x48\xd8\x33\x40\x26\x87\x60\x90\x72\x49\xd7\x2f\x37\x2a\x1e\x1f\xb7\x74\xb4\x0e\x28\x08\x7d\x53\x2e\xe1\xf3\x67\x40\x16\x67\x1b\x57\x82\xe1\x61\xf3\x46\xe2\xe3\x1a\x53\x85\x19\x88\x4c\x37\x3a\x5c\x9d\x90\xf3\x9d\x94\x1b\x15\x1a\xc4\xe6\xe1\x06\x85\xb4\x1c\x08\x69\x18\xe0\x9b\xf5\xe9\x93\xac\x7f\x1f\x79\x21\x77\xa8\x97\x1b\xc5\x4a\x31\x21\x76\x67\x4c\x7b\x59\x2d\x42\x08\xe9\xde\x21\x84\x3c\xb0\x0a\xd9\x9a\x20\xb4\x6a\x0e\x9d\x56\x9e\x3f\xb2\x3d\x5d\xbd\x58\xe9\xf9\x76\x68\xdf\x84\x3c\x3b\x09\x84\x7c\x9a\x23\x21\x3d\x86\x9c\xf1\x75\xd8\xd2\xd6\xf1\x87\x71\x45\x91\xd7\xe9\x29\xab\x6f\xad\xe0\xe6\x1d\x2d\x3d\x4f\x2f\x9c\x09\x44\x46\xa6\xc9\x11\xd9\x8c\x42\x2d\xca\x1d\xfb\x30\x71\xdd\x25\x02\xb3\x40\x96\xed\x83\x33\xa6\x5b\xb3\x36\xef\x82\xb7\xeb\xed\x8b\x50\xe0\x8f\xfd\x3d\x17\xb2\x6f\x3e\x83\x4f\x0c\x3c\xd5\xff\xaa\x27\x86\xee\x23\x83\x27\x98\xdf\x74\xbe\xd6\xa9\x29\xd4\x01\xd4\x24\x9e\x90\x04\xf3\x9b\x9d\x11\x1b\xd6\x74\x45\xa3\x63\xf1\x70\x39\x38\xbb\x9a\x49\x2b\x25\x17\x4c\xa5\xad\x79\xdc\x98\x5b\x23\x32\x4f\xcb\x91\x77\xeb\xbd\x5c\xf3\xd3\x88\x61\xc3\x26\x75\x2f\xa3\x5b\x0a\xe6\xa4\x79\x71\xd0\x26\xa3\xb5\x40\x05\xf0\x7c\xd4\xb7\x97\x7d\xa2\xf1\x6c\x66\x47\x32\xda\x86\xf4\x39\xcc\xb4\x98\xa4\xad\x0c\x8c\xe9\xec\x4c\x08\xfd\x8a\x43\x33\x77\x2b\xe6\xe6\x8d\x4a\x23\xbf\x51\xd5\x26\x55\xec\x56\xd4\xab\x74\xdf\x12\x0f\x03\x4f\x40\x7a\xa4\xdd\x7b\x0c\x65\x38\x9d\x41\x7e\xf8\x28\xaf\xdf\xd8\x17\xc5\xcc\x2f\xbe\x06\x6b\x90\xa1\x2a\x8c\x3e\x0e\x55\x62\xcf\x2b\x60\x0e\x48\x43\xe4\x90\x2f\xdb\x27\x3e\x31\xef\x5e\xf1\x8d\xbd\xe4\x4b\x02\xeb\x58\x47\xd0\xf1\x4c\xf6\xca\xe3\x7c\x19\xb5\x32\xa6\x50\x71\x9c\x2f\xe7\x5d\x61\xda\xd5\x89\xa3\xb8\x23\xbc\xe7\x5a\xf9\xbf\x90\x85\xdb\x7b\xfd\x0e\x1b\xcf\xf5\xdb\xf3\xc9\x12\x3f\x59\x7b\xdf\x55\x41\xf8\xa7\xdb\xbc\xdc\x63\xc6\x5f\xd3\x37\xec\xb3\xd8\xbd\xbd\xc3\x53\x96\x4a\xdc\x9c\x1e\xc3\xab\x92\x0a\x49\x05\x35\xf7\xf2\x27\x44\x42\xdd\x27\x0a\x92\x0a\xa1\x56\x65\x85\x19\x24\x35\x95\x3d\xf6\x97\x4b\x59\xa2\x92\xbb\xa4\x46\x38\x3e\xf5\x7a\x4b\x6e\x8b\x12\x99\xc1\x58\x96\xaa\x57\x43\x46\x7a\xc5\x9b\x18\x58\x93\x77\x06\x56\xab\x2a\x2d\xe5\x43\x7c\xa9\x4a\xd1\x46\x09\xab\x91\x41\x6b\x1b\xb4\x37\x97\xec\xfa\x1d\x8f\xc8\x22\xc7\xad\xa7\x87\x7d\xcd\x51\x87\x81\xee\xef\x3e\x9c\x3f\x7a\x70\xb6\xdd\xa2\xaf\x3b\xbe\xd7\xff\x31\x89\xef\x93\x6e\x2a\xef\x0f\x1f\x8c\x12\xc7\x87\xfa\x88\x2f\x68\x23\x7a\x5d\x7e\xb7\x3d\x68\xfe\x59\x6e\x6f\x62\xe5\x9e\x20\xe9\x45\xd4\x6e\xb1\xba\x2f\x00\x3c\xcb\xeb\x45\xcd\xa8\x88\x39\xce\x7c\x83\xce\xef\xd7\x68\x7e\x98\xfd\x6b\xa2\xd1\x0e\x73\xc7\xf9\x72\x98\xc3\xc3\xe1\xc7\xb5\x5c\xfa\x39\x16\x9a\x46\xb6\xad\xa2\x97\x42\x9e\xc8\xc5\x9d\xea\x75\xf7\xe7\x11\x3b\x2f\x18\x7f\x4c\x48\x79\xf6\x5c\xc8\x2f\xb4\xdd\x18\x28\xa9\x3a\x3f\x3a\xbc\xac\x16\xed\x1e\x3f\x8a\xfb\xbb\xad\xa9\xe9\x21\xed\xa6\x28\x14\x45\x53\x0f\xc4\x6b\x43\x47\xfd\x48\xa7\x9f\xd9\xbb\xb1\x4e\xaf\xb9\x68\xa7\xa3\xa4\x0d\x70\xd7\x65\xb5\x4a\xd4\x4c\xea\x77\xcd\x84\xb9\x8b\xb9\x4d\x9e\xc0\xf9\x99\xf9\xa1\x1c\x2b\x89\x08\xdd\x27\xf5\xbb\x0a\x73\xf1\xe8\xf1\x46\xcd\x75\x68\xb0\x12\x0e\x4d\xce\xb2\xa9\x6f\xc4\x88\x4f\xdc\x0f\x58\xda\x41\x60\x4b\x74\xdf\x4f\x3b\xff\x11\x00\x00\xff\xff\xe4\x37\x46\x7d\x35\x2b\x00\x00") +var _templateDialectSqlQueryTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3a\x6b\x6f\xdb\x48\x92\x9f\xa9\x5f\x51\x23\xf8\x06\xa2\x21\xd3\x76\xee\x70\xc0\x29\xf0\x01\xde\x38\x06\x84\xcc\x64\xb2\xe3\xcc\xcc\x07\x43\x98\xa1\xc9\xa2\xdc\x10\xd5\x54\xc8\x96\xe3\x40\xe1\x7f\x5f\x54\xf5\x83\xcd\x87\x64\x27\xf3\xd8\x5d\x60\x3f\x24\x96\xba\xab\xab\xaa\xeb\x5d\xd5\xda\xed\x4e\x8f\x47\xaf\x8a\xcd\xa7\x52\x2c\xef\x15\xbc\x38\x3b\xff\xbf\x93\x4d\x89\x15\x4a\x05\xd7\x71\x82\x77\x45\xb1\x82\xb9\x4c\x22\xb8\xcc\x73\x60\xa0\x0a\x68\xbf\x7c\xc0\x34\x1a\xbd\xbf\x17\x15\x54\xc5\xb6\x4c\x10\x92\x22\x45\x10\x15\xe4\x22\x41\x59\x61\x0a\x5b\x99\x62\x09\xea\x1e\xe1\x72\x13\x27\xf7\x08\x2f\xa2\x33\xbb\x0b\x59\xb1\x95\xe9\x48\x48\xde\xff\x6e\xfe\xea\xf5\xdb\x9b\xd7\x90\x89\x1c\xc1\xac\x95\x45\xa1\x20\x15\x25\x26\xaa\x28\x3f\x41\x91\x81\xf2\x88\xa9\x12\x31\x1a\x1d\x9f\xd6\xf5\x68\x44\x77\x80\xcb\x34\x15\x4a\x14\x32\xce\x21\x13\x98\xa7\x15\x64\x85\x26\x7e\xb7\x15\x79\x8a\x65\x04\x0c\xbd\xdb\x41\x8a\x99\x90\x08\xe3\x54\xc4\x39\x26\xea\xb4\xfa\x90\x9f\x7e\xd8\x62\xf9\xe9\x54\x9f\x1c\x43\x5d\x8f\x82\xdd\xee\x04\x3e\x0a\x75\x0f\x47\xd1\x75\x51\xa2\x58\xca\x37\xf8\xa9\xe2\xad\x80\xd6\xaf\xdf\x54\x70\x57\x14\xb9\x86\x44\x99\x02\x63\x77\x1f\x0f\x52\x1a\x6b\x60\x38\xda\xac\x96\x30\xbb\x80\xa3\xe8\x26\x29\x36\x18\xbd\x8b\x93\x55\xbc\x44\xbb\x6b\x58\x27\x88\x4d\x5c\x25\x71\xee\x00\xff\x66\x76\x0c\x60\x89\x09\x8a\x07\x0d\xe9\x3e\xbb\xe3\xc4\x4d\xb6\x95\x09\x4c\x5a\xb0\x75\x0d\xc7\x3e\x95\xba\x0e\xa1\xfa\x90\x5f\xe6\xf9\x24\x51\x8f\x90\x14\x52\xe1\xa3\x8a\x5e\xe9\xbf\x21\x4c\x6e\x17\x0c\x1f\xbd\x8d\xd7\xc4\xe2\x14\xb0\x2c\x8b\x32\x84\xdd\x28\x78\x88\x4b\x98\x8c\x82\x40\x16\x29\x56\x70\x01\x1d\xd0\x1d\x49\xed\x90\x44\x9d\x48\x2f\xa0\xc3\x63\x64\x76\x0c\x02\x23\xdd\x20\xf8\xb5\xda\x60\x32\x00\xce\xf2\xbd\xd9\x60\x32\x09\xdb\x34\x5f\xa7\x4b\xb4\xd4\xf2\x22\x4e\x31\x7d\xff\x69\xa3\x99\xdd\xed\x20\x47\x09\x11\xd4\xf5\x82\x74\xba\x23\x18\x3e\x5b\xc6\x72\x89\x70\x84\x24\xd8\xc8\x1c\xa6\x9d\x3e\x8b\xbb\x9d\xd3\x11\xda\x6b\xc3\x37\x17\x20\x45\x3e\x75\xe8\x1c\xf7\x41\xdd\xb9\x4f\x78\xd8\xe2\x5a\x9b\x6f\xfc\xab\x04\x22\x23\x19\x18\x46\xc5\xd4\x63\x76\xb7\x03\x91\xc1\x52\xc1\x91\x80\x33\x62\xe7\xf3\x67\x02\xd5\x24\xbf\xf0\x0e\xee\x1c\x68\xe1\x78\x0a\x53\xe5\x16\x79\xcd\x31\xda\x5c\x53\x64\x60\x01\xf5\x39\x56\x5b\xf4\xb6\x48\x31\x7a\x55\xe4\xdb\xb5\x24\x0c\xf1\x66\x83\x32\x9d\xf4\xf7\xa6\xac\x5e\xcf\x2d\x7c\xc9\x44\x51\x14\x1a\x51\xfa\x44\x35\x96\x9b\x24\x96\x3f\xc7\xf9\x96\x15\x4c\xc6\x3f\x09\xe1\x76\x21\xa4\xc2\x32\x8b\x13\xdc\xe9\x7b\x90\xb9\x92\xb4\xbe\x6d\x19\x6b\x52\xc8\x4c\x2c\x67\x3d\xd3\xd2\xeb\xb5\x67\xe6\x86\x71\xfe\x3a\x05\xfa\x43\x1c\x3d\x68\xba\xb3\x0b\x5e\x89\x2a\xc7\x4a\xd7\x24\xfb\x6a\xee\xc9\xeb\xc1\xde\xc1\x90\xd2\xdf\x35\xad\x28\x5b\x59\xbc\x9e\x2c\xda\x1a\x28\x51\x6d\x4b\x09\xfa\xd8\x28\x70\xf2\xb9\xac\x2a\xb1\x94\x56\x36\x86\x4a\x14\x45\x9e\x84\x42\xed\xdf\xcc\x88\xc8\xc8\x43\xf4\x45\x43\xb8\xb8\x80\x33\xcd\x9f\x41\x9f\xad\x55\xf4\x9a\x80\xb3\xc9\xd8\x86\xb5\xba\x9e\x81\xa1\x92\xc4\x79\x8e\x29\xdf\xac\xd8\x2a\xfe\x2a\xe4\x12\x1a\x1d\x8d\x89\xf9\xda\x53\x08\x13\xba\x6d\x48\x9e\x9c\x2f\xf6\x7b\x33\xcb\x82\x17\xa2\xb6\x63\x7b\xdf\xf6\xc8\x85\x8f\xc6\xcc\xa5\x11\xa5\x16\x85\x96\x67\x3d\xa2\x8b\x63\xc9\x71\xb5\xfa\x90\x2f\xcb\x78\x73\x1f\xfd\x9d\x22\x0c\x59\x69\x45\x71\x72\xda\x33\x93\xb4\xa4\x4f\x53\x60\x41\x87\x2f\xf9\xbc\x76\x22\x96\x99\xa5\x2c\x72\x0e\xa0\x96\xca\x90\x78\x3d\x26\x49\xe5\x22\x1f\x59\x63\xf7\xe3\x52\x4b\x18\x4e\x44\xf8\xa8\xe8\xb2\x47\x30\xfe\x11\x93\xb1\xc7\xe1\x98\xa0\xc7\x74\xd6\x46\x16\x50\xb8\xde\xe4\xb1\x1a\xcc\x89\x18\x2f\xb1\x24\x41\x0a\xb9\x1c\xdb\x18\xe8\x8b\xd2\xff\xdc\x67\xf8\x8b\x52\xcf\xab\x62\x2b\xd5\x9e\xe4\x23\xa4\xf2\x13\x8e\x0e\xff\xb3\x27\xe2\xbf\xe1\xc7\xa9\x8e\x09\x3c\x5b\x75\x5f\xc6\xfc\xeb\x47\x51\xed\x63\x9e\x92\x8a\xcf\xbd\x9c\x5a\xab\xea\x72\xe0\x4b\x21\x74\xe6\xd7\x37\x9f\x2c\xce\x2b\x9c\xee\x75\xbc\xe4\x1e\x93\x15\x20\xb1\x84\x32\xc1\x19\xfc\xd7\xc3\x98\x69\x6a\xab\xb6\x7a\x82\xff\x87\xb3\x2f\xd5\x93\x27\x60\x38\x6e\x3b\x05\xad\xb6\x94\xf3\x6d\x7f\x9f\xee\x40\x1a\x98\x79\x9b\xf4\xdd\xee\x05\xef\xe3\xbb\x1c\x67\xbd\xc0\xcf\xcb\x9c\x49\x4d\x6e\xe8\x83\xd8\xa4\x41\x40\xf3\x2b\x9f\xc0\x35\x15\x76\x8e\x42\x40\x11\x61\xa6\xeb\xc4\x88\x91\xcc\xaf\x22\x5a\x23\x8d\x55\xca\x96\x37\x0c\xaa\x71\xf6\x69\xd9\x63\x7c\x22\x96\xca\x1e\xe0\xff\xf9\xbf\xeb\xb2\x58\xf7\x73\x48\xf5\x81\xcb\x81\x9f\xa4\xf8\xb0\xc5\x19\xe7\xce\xa9\x0d\x01\x9b\x6a\xc8\x22\x36\x25\xa6\x22\x89\x15\x56\x2f\x39\x48\x6c\xaa\x90\xd4\xc6\xc6\xa0\x63\xf9\x3b\x0b\x61\xc3\x79\x85\x39\x97\xcd\xac\x9f\xe8\xc6\x7c\x0b\x75\xc8\xa6\xba\x58\x70\xa1\xc8\x31\x64\x63\x33\xcd\xa6\xba\x15\x0b\x77\xd4\x65\x93\xda\x05\x28\xb1\x16\x6a\x88\x41\xde\x78\x69\xf6\x3d\x4b\xd5\xcc\x7d\xc7\xcb\x17\x70\xcc\xfb\x16\x59\x91\x65\x15\x0e\x62\xd3\x3b\x2f\x2d\x44\x0f\xdf\x0f\x7a\xfd\x02\x8e\x35\xc4\x61\xe1\x15\x65\x8a\xe5\x3e\xb9\xfd\x40\x9b\x7f\x9e\xcc\x8c\x93\x31\xad\x2f\x0b\x25\xec\x2c\xc6\xbd\x1c\x2b\x44\xd2\x6b\x08\x68\xeb\x4a\x47\xeb\x2e\x4e\x13\xc6\xdc\x76\x18\x8e\x02\x75\x4e\x87\x6c\x2f\xc4\xce\x34\x19\x74\xb1\x70\x14\x38\x51\x78\x27\x34\x17\x13\x75\x6e\xbd\xac\x77\xda\xac\x53\xe6\xe4\x7f\x64\xff\x13\x75\xae\x83\xd8\x80\x1b\xf8\xaa\x75\x14\x07\x03\xa2\x07\x60\xf9\x70\xdf\x9f\xc9\x0d\x2b\x84\xb4\xf8\xeb\x14\x36\x8d\x22\xf7\xfb\x1a\xb3\xb5\xf1\x55\xfb\x2c\x04\x6c\x6f\x83\x67\xbf\xd2\xe8\x4f\x4f\x8d\x63\x89\x0a\xd6\xb1\x4c\x63\xee\x86\x89\x11\x03\x9b\xe4\xf1\xb6\xc2\x08\x7e\x41\xa8\x54\x5c\x2a\x7d\x86\x4b\x80\x14\xb3\x78\x9b\x2b\x5d\xfc\x4d\x21\x96\x29\x14\x0f\x58\x96\x82\x1a\x75\x05\x77\x98\x17\x1f\xa9\x43\x90\x88\x29\x75\xf3\x9e\x98\xb5\x97\x4d\x8c\x8f\x85\xda\x8b\x27\xeb\x58\xdd\x47\xdf\xc7\x8f\x73\xa9\xfe\xfb\x45\xf8\xd5\x81\xc1\x51\xd1\x58\x75\x64\x68\x25\x26\x0b\x31\xe2\xf6\xb6\xe9\xa8\x4f\x8f\x75\xfa\x39\xdd\xc4\xfa\x7e\x42\x62\xc5\x5d\x3e\x2f\xc3\x12\x25\x96\xb1\x12\x85\x64\x11\x31\x54\x91\x41\x0c\x4b\xf1\x80\x12\x30\x5d\xe2\x73\xe6\x00\x74\xae\x99\x02\x1c\x49\xae\xb2\xb8\xf7\x21\x0e\x88\x1c\xd7\xa9\x1f\x8d\xc8\x3d\x06\xb2\xb2\x58\x1b\x0a\xfa\x2c\xfa\xed\x3d\x55\x5e\x2d\x34\xc4\x10\xa1\x21\x0d\x80\x2a\x98\xff\x65\x49\x91\x9c\x76\x99\x7d\x55\xb4\xf0\xf9\x9d\xbe\x45\xfb\x63\x23\xf3\x51\x50\x29\xdc\xb4\xca\xd5\xb7\xf8\xf1\x46\xe1\x86\xba\xf3\x26\x1f\x92\x6f\x92\xba\x64\x3f\xc5\x42\x6f\x5d\x2f\x74\x92\xdd\x90\xa3\x9a\xb8\x15\x4e\x7d\x5a\xef\x0b\xa6\x84\x3a\xc3\x0e\x93\xeb\x6f\x7a\xab\x6d\xc2\x6d\xe4\x24\xd1\x89\xfb\xa6\x0f\xfd\x88\x39\x1f\x74\x5c\x62\x34\xaf\xe6\xf2\x01\xcb\xaa\x59\xeb\x5d\x10\x35\x3f\xdd\x7c\x4e\x42\x17\x19\x6d\x7f\xff\xe2\x7b\x38\x31\x3d\xf7\x1e\x0c\xef\xde\x78\xc7\xa3\x28\x72\xfd\x70\x5e\xe1\x53\x67\x75\xc0\xf2\xce\xfb\xcd\xb4\x3e\x4b\x57\x0f\x47\x01\x5b\x1a\x47\x50\x4f\xcb\x37\xa8\xde\xa2\x58\xde\xdf\x15\x65\xf5\x64\x3e\x98\x02\x59\x49\xb8\xc7\xb7\xc8\x86\x9f\xf6\xad\x58\xbb\x93\x67\xf7\xce\xcd\xb8\xa9\x7a\xce\xb8\xad\x2c\xd6\xff\x8e\x6e\xc6\xda\x10\xe9\x50\xc8\xd3\x23\x17\x8a\xb4\x5c\x1d\xce\xab\x1b\x55\x52\xab\x3b\x91\x85\xd2\x4b\x3f\x55\x58\x5e\xb1\x48\xd2\x10\xea\x5a\xa4\x93\x90\xd4\x90\xb3\x6d\xce\xaf\x1a\x95\xfc\x75\x9e\x2c\xd2\xff\x78\xec\x5f\xef\xb1\xbf\xd3\x5d\x0f\xf8\x55\xbb\x65\x3f\xe8\x23\x87\xcd\x9d\x01\x44\x66\x9c\x6e\xc0\xdc\xf7\x0d\x0d\x5f\x9a\x23\x5e\xd2\x6f\xab\x45\x0b\x2b\x5b\x71\xd1\xbe\x8e\x57\x38\xb9\x5d\x98\x6b\xff\xac\xab\x95\xb3\xa9\x37\x12\xe1\xca\x5a\xa4\x0d\xf4\x3a\xde\xdc\xfa\x9d\x1b\xd4\x75\x77\x38\xdd\x39\x6d\x6a\x37\x3b\x60\xd2\xe5\x9b\x9e\xe3\xe9\x5a\x5e\xa4\xd5\x2d\x47\xae\xf9\xd5\x02\xf4\x04\x8a\xd7\x89\x49\x37\x7e\xcb\x56\x76\xf6\x36\xbf\x72\xe5\xbe\x9b\x7e\x07\x01\x45\x1a\xe2\xf3\x76\xd1\x76\x07\xc3\xa3\x83\x21\x94\xad\x8b\xf4\x40\x17\x9d\x11\x3a\x53\xe3\xff\x06\xba\x6b\xd2\x66\xab\xc3\x0e\x02\x5a\x9a\x75\x40\x9a\xdd\xc0\x78\xd7\x6c\xc8\xdd\x34\xc4\x9e\x3e\xfc\x80\xe7\x1d\x68\xcd\x07\xbc\x4d\x1f\x31\x7f\x5c\x0b\x3b\x33\xdd\xd8\x60\x1b\x16\x04\x55\xf4\xcb\x3d\x96\x1c\x40\xa2\xb9\x1d\xd9\x3d\x83\xd8\xad\x0e\xcc\x9d\x9b\x9e\x37\x91\xf7\xcc\x39\xd7\x62\x0a\xd9\x8a\x1b\x87\xd0\xe7\x90\x90\x16\x5b\xae\x73\xc7\x44\xfd\xed\x36\xcf\xe7\x52\xfd\xef\xff\x8c\xdd\xa4\xbd\x1b\xdf\xcd\x94\x9d\x4e\x5d\xe8\x4d\x3a\x64\xf4\xeb\x05\x7a\x83\x5d\xc8\x83\xc8\x1b\x0b\xe9\x93\x10\x92\x28\x34\x10\x7b\xe9\x34\x23\xd7\x99\x9b\x8a\xbf\xf0\xc7\xe2\x46\xce\xa6\x0e\xef\xec\x7d\x6b\xaf\x53\xd7\xbb\x7a\xaa\xa7\xe6\x42\xf2\xb7\xda\x97\x95\x1e\xfb\x1a\x0a\xc5\x56\x4d\x41\x48\xd8\x33\x59\x26\x87\x60\x90\x62\x45\xd7\x2f\xb6\x2a\x9a\x1c\x37\x74\xb4\x0e\x28\x08\x7d\x53\xac\xe0\xf3\x67\x40\x16\x67\x13\x57\x82\xe1\x29\xf4\x56\xe2\xe3\x06\x13\x85\x29\x88\x54\x77\x40\x5c\xb6\x90\xf3\x9d\x14\x5b\x35\x36\x88\xcd\x8b\x0e\x0a\x69\x39\x10\xd2\x30\xc0\x37\xeb\xd3\x27\x59\xff\x3e\xf2\x42\x76\xa8\x17\x5b\xc5\x4a\x31\x21\xb6\x33\xbf\xbd\x2c\x97\x63\x18\xd3\xbd\xc7\x30\xe6\x49\xd6\x98\xad\x09\xc6\x56\xcd\x63\xa7\x95\xe7\xcf\x72\x4f\xd7\x2f\xd6\x7a\xf0\x3d\xb6\x8f\x45\x9e\x9d\x04\x42\x3e\xcd\x91\x90\x1e\x43\xce\xf8\x5a\x6c\x69\xeb\xf8\xc3\xb8\xa2\xc8\xeb\xf4\x94\x56\xb7\x56\x70\x8b\x96\x96\x9e\xa7\x17\xce\x04\x22\x25\xd3\xe4\x88\x6c\x66\xa4\x16\x65\xc7\x3e\x4c\x5c\x77\x89\xc0\x2c\x90\x65\xfb\xe0\x8c\xe9\xd6\xac\x2d\xda\xe0\xcd\x7a\xf3\x54\x14\xf8\xef\x01\x9e\x0b\xd9\xc7\xa0\xc1\xb7\x07\x1e\xf7\x7f\xd5\xdb\x43\xfb\xf5\xc1\x13\xcc\x6f\x3a\x5f\xeb\xd4\x34\xd6\x01\xd4\x24\x9e\x31\x09\xe6\x37\x3b\x3c\x36\xac\xe9\x8a\x46\xc7\xe2\xe1\x72\x70\x7e\x35\x97\x56\x4a\x2e\x98\x4a\x5b\xf3\xb8\xf9\xb7\x46\x64\xde\x9c\x43\xef\xd6\x7b\xb9\xe6\x37\x13\xc3\x86\x4d\xea\x5e\x46\xb7\x14\xcc\x49\xf3\x14\xa1\x4d\x46\x6b\x81\x0a\xe0\xc5\xa8\x6f\x2f\xfb\x44\xe3\xd9\x4c\x47\x32\xda\x86\xf4\x39\x4c\xb5\x98\xa4\xad\x0c\x8c\xe9\x74\x46\x87\x7e\xc5\xa1\x99\xbb\x15\x0b\xf3\x78\xa5\x91\xdf\xa8\x72\x9b\x28\x76\x2b\x6a\x62\xda\x8f\x8c\x87\x81\xa7\x20\x3d\xd2\xee\xa1\x86\x32\x9c\xce\x20\x3f\x7c\x94\xd7\x6f\xec\x53\x63\xea\x17\x5f\x83\x35\xc8\x50\x15\x46\x1f\x87\x2a\xb1\xe7\x15\x30\x07\xa4\x21\x32\xc8\x56\xcd\xdb\x9f\x58\xb4\xaf\xf8\xc6\x5e\xf2\x25\x81\xb5\xac\x23\x68\x79\x26\x7b\xe5\x71\xb6\x0a\x1b\x19\x53\xa8\x38\xce\x56\x8b\xb6\x30\xed\xea\xd4\x51\xec\x08\xef\xb9\x56\xfe\x2f\x64\xe1\xf6\x5e\xbf\xc3\xc6\x33\xfd\x28\x7d\xb2\xc2\x4f\xd6\xde\xbb\x2a\x18\xff\xe9\x36\x2f\xf7\x98\xf1\xd7\xf4\x0d\xfb\x2c\x76\x6f\xef\xf0\x94\xa5\x12\x37\xa7\xc7\xf0\xaa\xa0\x42\x52\x41\xc5\x2d\xfe\x09\x91\x50\xf7\xb1\x82\xb8\x44\xa8\x54\x51\x62\x0a\x71\x45\x65\x8f\xfd\x49\x53\x1a\xab\xf8\x2e\xae\x10\x8e\x4f\xbd\xde\xf2\xc4\x4e\x0c\xf6\xcc\x08\xda\x83\x04\x97\x9f\x53\x67\x60\x95\x2a\x93\x42\x3e\x44\x97\xaa\x10\x4d\x94\xb0\x1a\x19\xb4\xb6\x41\x7b\x73\xc9\xae\xdf\xf1\x88\x34\x74\xdc\x7a\x7a\xd8\xd7\x1c\xb5\x18\x68\xff\x20\xc4\xf9\xa3\x07\x67\xdb\x2d\xfa\xda\xf1\xbd\xfe\xaf\x4c\x7c\x9f\x74\xe3\x7a\x7f\xf8\x60\x94\x38\x39\xd4\x47\x7c\x41\x1b\xd1\xeb\xf2\xdb\xed\x41\xfd\xcf\x72\x7b\x13\x2b\xf7\x04\x49\x2f\xa2\xb6\x8b\xd5\x7d\x01\xe0\x59\x5e\x2f\x2a\x46\x45\xcc\x71\xe6\x1b\x74\x7e\xbf\x46\xf3\xc3\xec\x5f\x13\x8d\x3a\xcc\x1d\x67\xab\x61\x0e\x0f\x87\x1f\xd7\x72\xe9\x77\x5a\xa8\x6b\xd9\xb4\x8a\x5e\x0a\x79\x22\x17\xb7\xaa\xd7\xee\xef\x26\x3a\x4f\x1b\x7f\x4c\x48\x79\xf6\x5c\xc8\x2f\xb4\xdd\x18\x28\x2e\x5b\xbf\x46\xbc\x2c\x97\xcd\x1e\xbf\x96\xfb\xbb\x8d\xa9\xe9\xe9\xed\x36\xcf\x15\x45\x53\x0f\xc4\x6b\x43\x47\xfd\x48\xa7\xdf\xdf\xdb\xb1\x4e\xaf\xb9\x68\xa7\xa3\xa4\x0d\x70\xd7\x45\xb9\x8e\xd5\x5c\xea\x07\xcf\x98\xb9\x8b\xb8\x4d\x9e\xc2\xf9\x99\xf9\x05\x1d\x2b\x89\x08\xdd\xc7\xd5\xbb\x12\x33\xf1\xe8\xf1\x46\xcd\xf5\xd8\x60\x25\x1c\x9a\x9c\x65\x53\xdf\x88\x11\x9f\xb8\x5f\xb6\x34\x83\xc0\x86\xe8\xbe\xdf\x7c\xfe\x23\x00\x00\xff\xff\xaa\xa5\x23\xce\x4e\x2b\x00\x00") func templateDialectSqlQueryTmplBytes() ([]byte, error) { return bindataRead( @@ -776,7 +776,7 @@ func templateDialectSqlQueryTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/query.tmpl", size: 11061, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/dialect/sql/query.tmpl", size: 11086, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -821,7 +821,7 @@ func templateDialectSqlUpdateTmpl() (*asset, error) { return a, nil } -var _templateEntTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x58\xdf\x6f\xe3\xb8\xf1\x7f\xb6\xfe\x8a\x39\xc1\x7b\x67\x1b\x0e\xb5\xdf\x7b\xfb\xa6\x4d\x81\x5c\x92\x05\x0c\x2c\x72\x6d\x93\x45\x1f\x16\x8b\x0d\x2d\x8d\x6c\x36\x32\xe9\x25\x29\x27\x81\xa0\xff\xbd\x18\x52\x94\x29\xdb\xc9\xa5\xd7\x27\xcb\xe4\xfc\xfc\x0c\x67\x38\xc3\xa6\xc9\x66\xc9\x95\xda\xbe\x68\xb1\x5a\x5b\xf8\xf5\xe3\xff\xfd\xff\xd9\x56\xa3\x41\x69\xe1\x13\xcf\x71\xa9\xd4\x23\x2c\x64\xce\xe0\xb2\xaa\xc0\x11\x19\xa0\x7d\xbd\xc3\x82\x25\xf7\x6b\x61\xc0\xa8\x5a\xe7\x08\xb9\x2a\x10\x84\x81\x4a\xe4\x28\x0d\x16\x50\xcb\x02\x35\xd8\x35\xc2\xe5\x96\xe7\x6b\x84\x5f\xd9\xc7\xb0\x0b\xa5\xaa\x65\x91\x08\xe9\xf6\x3f\x2f\xae\x6e\x6e\xef\x6e\xa0\x14\x15\x42\xb7\xa6\x95\xb2\x50\x08\x8d\xb9\x55\xfa\x05\x54\x09\x36\x52\x66\x35\x22\x4b\x66\x59\xdb\x26\x49\xd3\x40\x81\xa5\x90\x08\xe9\x46\x15\x58\xa5\xd0\xad\x8e\xb7\x8f\x2b\x38\xbf\x80\x25\x37\x08\x63\x76\xa5\x64\x29\x56\xec\xef\x3c\x7f\xe4\x2b\x24\xa2\xa6\x01\x8b\x9b\x6d\xc5\x2d\x42\xba\x46\x5e\xa0\x4e\x61\x1c\xd8\xf7\x5b\x62\xb3\x55\xda\x86\xad\x2c\x03\x12\xce\x6e\xf9\x86\xa4\x90\xcf\x64\xb0\xd3\x0d\x28\xad\xb0\x2f\x50\x2a\xef\xf9\x80\xd0\xe4\x6b\xdc\x70\x96\xd8\x97\xed\xe1\x8e\xd5\x75\x6e\xa1\x49\x46\xb9\x33\x12\x06\xea\x9d\xe4\x4c\x6d\x84\xb5\x7c\x65\x3a\x33\x46\x59\x06\x8b\x6b\x8f\x0b\x92\x5a\x96\x8c\x16\xd7\x5e\xec\xe2\x9a\xdd\x93\x8e\xb6\x85\x87\xb0\x70\xe7\x54\xdc\xf3\x15\xb4\xed\x43\x32\x6a\x9a\x33\xd0\x5c\xae\x10\xc6\xdf\xe7\x30\x2e\x09\xa7\x31\xfb\x24\xb0\x2a\x8c\x13\x3f\xea\xdc\x2c\x3b\x4e\xb7\x45\x12\xd7\x8a\x48\x48\xe9\x8e\x57\x35\x06\x0b\x52\x4f\xdc\x79\x94\x42\x49\xf4\x2c\x01\x00\x18\x9d\x94\xd3\x34\x20\x4a\xc7\x22\xaa\x8a\x2f\x2b\x62\x9b\x35\x0d\xa0\xa4\x6d\xcf\x12\xbc\xf0\xb4\x52\x59\x27\x07\xa5\x11\x56\xec\x68\xe7\x21\x16\xdd\x39\x47\x32\x2a\x83\x5e\xc8\xdb\x28\xf6\xea\x3c\x20\xf1\xf7\x93\xb0\x6b\x18\xb3\x9b\x62\x85\x7b\x40\xfc\xbf\x3d\x02\x1a\x2b\x6e\x85\x92\x26\x43\xb7\x43\x61\x57\x76\x8d\x1a\xa4\x2a\xd0\x84\xb3\xbc\xd2\x7c\xbb\x66\x5e\xc4\x7d\x00\xce\x00\xd7\x08\x4b\x14\x72\x05\x5b\xb5\xad\xc9\xca\x02\x96\x2f\x47\xe7\xe6\x1f\x35\xea\x17\x78\x5a\xa3\x04\xe4\x2b\xd4\x67\x95\xe2\x05\x71\x51\x3a\x20\xc5\x7d\xe4\xed\x8a\x99\xfc\xca\xc3\xbf\x8d\x92\xe7\xa9\x33\x2e\x7d\xd8\x3b\x79\x16\xbc\xcc\x66\x70\x59\x14\x82\x7c\xe0\x95\x8f\x99\x01\xab\x80\x17\xbd\x29\xc6\x2a\x4d\xf9\x52\x68\xb1\x43\xcd\xc0\x25\x9d\x63\x1e\xdb\xcd\xb6\xa2\x83\xb3\xd5\x42\xda\x12\xd2\x42\xf0\x0a\x73\x9b\x7d\x30\x99\x47\xdb\x0b\x4c\x61\xcc\xee\x3a\x29\x81\x57\x94\xb0\xe6\xe6\x3e\x44\xc7\x8b\x72\x30\xd3\xee\xb3\x1d\x6e\xb0\x93\x21\x7a\x87\xf1\xb5\x89\x4d\x3e\x3a\x0d\x9e\x27\xe3\xbd\x94\x2e\xb9\x5c\x01\x38\x3e\x03\x07\x99\xff\xbf\x9d\x86\xa3\x2a\xe0\xc5\xed\x4b\x41\x94\xa2\x48\x28\xb3\x41\x5e\xe2\x3b\xf3\xd2\xd3\x86\x42\x43\x86\x31\x07\xf2\x09\x09\x51\x96\x21\xfb\x22\xc5\x8f\x9a\x78\xbe\x7e\xeb\xb3\x64\xe6\xd9\x28\x2b\x7b\x89\x4d\xd3\xc1\x84\x47\x59\xc8\x42\x36\x9e\x48\xb1\x2c\x03\x3a\xc6\x58\x90\xb0\x18\x44\x21\x4b\xa5\x37\x0e\x47\x07\xa0\x46\xaa\xbd\xee\xb8\x97\xc0\x1d\xa3\x43\xee\x89\x9b\x4e\x02\x4c\x1c\xd9\x8f\x1a\x8d\xc5\x62\x4a\x30\x0f\xf3\x44\x51\x00\x28\x4f\x62\x8d\x5f\x9b\x06\x2a\x94\xce\xc8\x6f\x4b\xa5\xaa\x10\xf4\x0e\x72\x31\x1f\xc0\xfe\x0a\xea\xbf\xeb\x1b\x4d\xca\x6d\xad\xa5\x89\xf0\x3e\x40\xb6\x8b\x88\x06\x2e\x01\xb5\x56\x9a\x9c\x71\x75\xbb\x58\xa1\x13\x4e\xee\x10\xf2\x9d\x4b\x87\x3e\x74\xc5\x32\x0a\xcb\x9c\xc4\x75\xd4\xcb\xda\xf6\x02\xdc\xc5\xda\x83\xce\x92\x51\x59\xcb\x1c\x26\x27\x8e\xda\xf4\x75\x8f\x26\x53\x98\xfc\x99\xd3\x30\xf7\xde\x4d\xe9\xf8\x8e\x44\x09\xc8\x22\xc8\x09\xf1\xb1\x20\xb8\xdd\x76\x28\x03\xb1\x74\x5a\xf6\x7c\x27\x61\xbc\xb8\x00\x29\x2a\xcf\xdd\x17\x53\x82\xf0\xe0\x94\x47\x67\xe3\x10\xc8\x79\xcf\x7b\x04\x1a\xf3\x5b\x3e\x98\xa4\x68\x0e\x3f\xdf\x2a\xfb\x89\xf6\x6e\xc8\xad\xa6\xe2\x4b\xac\xce\x21\xf2\x7b\xdf\x4c\xb0\xcf\xb4\xe9\x3d\x68\x83\x7b\xe1\xb4\xf7\x52\x4f\x3b\x36\x27\x6d\x89\xe7\x3b\x54\xff\xd9\xf9\xe1\xf5\x93\xab\xe7\xfe\xa6\xed\x9d\x4d\xdb\x64\xd4\x26\x91\xb2\xe8\xd3\x35\x41\xae\x80\x9e\xac\xd1\x05\x52\xcf\x96\x29\x89\x07\x15\xba\x69\x8e\x2a\x70\xdf\x15\x8d\x35\xe6\x48\x37\x81\xef\x18\xfe\x19\xfe\x75\xdb\x51\x4f\x81\x9e\x62\x7f\x83\xba\xbb\x9a\x4e\x63\xb8\x32\x20\x75\x77\x5b\x7a\x8c\x48\x9f\x70\x8e\xbe\x6d\xe1\x47\x8d\x5a\xa0\x79\xa5\xa4\xc5\xc5\x2e\x6c\xf4\x47\x7f\x60\x74\xdb\xc2\x2c\xa6\x9a\xc6\x5a\x26\x53\x38\x3c\xd4\xe1\xfa\x6d\xf6\xa1\x99\xfc\x1c\x0b\xb8\xaa\x04\x4a\xdb\xc0\x81\x16\xe6\x1b\xb9\x76\xca\x62\xf9\x07\x44\x53\x1f\xba\x3e\x5c\x59\x06\x5f\xb6\x05\x81\x1e\x2a\x0a\x87\x65\x2d\x2a\xea\xa3\xa9\x16\xd6\xb4\x49\x15\xcd\xb5\xc2\x43\x67\xb3\x0c\x6e\x95\x45\xb0\x6b\x6e\xe7\xf0\xa2\x6a\x90\x88\x05\x5d\x87\x39\xaf\xaa\x21\xf1\x17\xf9\xa4\xf9\x76\x32\x85\x25\x96\x4a\xa3\xa3\xe8\xc5\x6e\xd0\xae\x55\x31\xf7\x15\xea\x40\x4d\xd2\x55\x2a\x6f\x1e\x16\x50\x6a\xb5\x01\x0e\x56\x73\x69\x78\x4e\x45\x7b\x0e\x5c\x16\x2e\x18\xd1\xa2\x63\xca\xd5\x86\x9a\x2f\x2c\xa8\x72\x69\x55\x55\x54\xb9\x78\xfe\xc8\x92\x77\xc5\xc9\x23\x13\x42\x14\xd6\xfd\xea\xef\x12\x29\x42\x7f\x2e\x40\xbd\x88\xe3\xf0\x74\x31\x71\x70\x41\xed\x7e\x4c\xe8\xb7\xa9\xcd\x27\xb0\xff\x08\x10\xe0\xa5\x45\x0d\xc2\x13\xe6\x95\x32\x58\xcc\x49\xac\x51\x9e\x9f\xc2\x23\xf1\xd9\xf6\x67\xfc\x49\x54\x15\x2c\x11\xf0\x19\xf3\x9a\xf0\xb2\x6b\xad\xea\xd5\xda\x69\xf6\x6d\x18\x3c\xad\x45\xbe\x86\x5c\x23\xf7\x04\x03\xb8\xdf\x8b\x68\x38\x06\x83\x75\x02\xd2\x3e\xcf\x41\x3d\x52\x9e\x9e\x46\x8d\x75\xcd\xe0\x64\x66\x9f\xaf\xdd\xe7\x34\xa1\xba\xfd\x93\x7a\x74\x99\xb2\xe5\x52\xe4\x93\x34\xcc\x60\x6d\x7b\x7e\x34\x32\x51\xd9\x1d\xe0\xc4\xc3\xf0\x94\xba\xb4\x18\xbd\xa9\x19\x2e\xc0\x3e\xb3\x42\xef\xfa\xa0\x1f\x90\x77\xa1\xbb\xb3\xda\xb5\x0e\x9b\x6d\x85\x1b\x94\xd6\x47\xaf\xdc\x58\xe6\x77\x50\xbf\x13\x2b\x4f\x3e\x99\x52\x7f\x46\x12\x9b\x64\xb4\xe3\xba\xcf\x4e\xbf\x6a\xd8\x6f\xfe\x7f\x32\xea\x36\xd8\xbf\xb4\xb0\xd8\x31\xa7\xb1\xc8\x09\xb9\x79\x8a\xca\x19\xe7\xab\xf5\x24\x15\xc5\xc5\x87\x5d\x3a\x3f\x0a\xc3\xe2\x7a\x3a\x1d\x74\x88\xe2\xf4\x10\x17\xee\xd8\xe1\xd4\x44\x17\xd2\x49\x03\xe7\x30\x98\xe2\x2e\xfe\x6a\x02\xd7\xdf\xc8\x5c\x7f\xa7\xf9\xd9\x2a\x5c\x71\x63\x53\xc6\x23\xc0\x07\xc3\x3e\x50\xc3\xdf\x1b\x7b\x34\xf8\xc5\x57\xff\x60\xf8\x0b\x97\xff\x2e\x9c\x3b\x53\x42\xdb\xfe\x05\x76\xf0\xd3\xe0\xde\x7f\x97\xe5\xce\xdc\x81\xa6\x85\xb9\x17\x9b\x5e\xcf\x69\x31\x3b\xf6\xc9\x35\x9f\x13\x2b\x36\xc8\x2e\x6f\xef\x16\x57\xd3\x48\x90\x73\x3d\x48\xeb\x8e\xd6\x9b\xf2\x66\xbb\x43\xee\x37\xc9\x07\xa1\x77\x71\x9f\xed\x06\xfa\xfb\x76\x22\x6a\x31\x22\xa9\xff\x0d\x32\xaf\x02\x73\x4a\x48\x1f\x8d\x57\xf1\xf9\x23\x78\xde\x94\x7a\x20\xe2\x2d\x9e\x63\x88\xf6\x52\x22\x31\x32\x3e\x69\xfd\xbf\xc3\x01\x32\x7c\x0f\x14\xfd\xf6\x62\x71\xf2\xcb\xf4\x97\x69\x5f\x5a\xc2\x76\xa8\x01\x61\x52\x20\x57\xd9\xe2\x7a\xe0\x6c\x96\x81\x28\x06\x03\x01\xf5\x39\x1a\xbb\x47\x35\x3f\xd7\x74\xdd\xca\xe2\x3a\xbc\x92\xbc\xab\x04\x89\x62\x32\x75\xd2\x9a\x64\x24\x8a\x39\x7c\xa7\x3c\x31\x56\xe7\x4a\xee\xd8\xa5\x55\xe2\x50\x00\x55\x89\xde\x09\x51\x24\xc7\xbd\xa1\xa9\x44\xee\xda\xb4\x6d\x55\x6b\x5e\x0d\x2f\xfa\x3d\x81\xaf\xd8\x1c\xb6\x5c\x1b\x97\xac\x7e\x59\x95\x07\x3d\x48\x3f\xd2\xf6\x6c\x5f\xbf\x0d\x9c\x70\x5a\xdd\xb8\x88\xcf\x96\x0c\x19\x43\x7a\x47\xb4\xe9\x9e\xc7\x57\xfe\x37\x9e\x16\xba\xb6\x75\xc3\xe5\xcb\xf1\xcb\xc2\xe9\xa7\x83\xa8\xc7\x3a\x0d\x75\x6c\xf4\x14\xfc\x55\x33\xc9\xcb\x55\xf7\xe9\x06\x1a\xea\xc0\xbe\x0b\x32\xca\xd7\xdc\x23\x19\xdd\x5c\x1d\xad\x7d\xfd\x2e\xbe\x75\x17\x17\x5c\x40\x5e\xae\xe8\x66\x1b\x98\xd3\x34\xd9\x0c\x2e\xf7\x0f\x13\xee\xcd\x80\xda\x24\x3a\x4f\xfe\x2d\xe0\xcc\xf2\x95\xe9\x1e\x31\x0e\xdf\x3a\xa3\xf7\x2c\xf7\x9a\xd5\xbd\x58\xdc\xf3\x95\x9f\x72\xfd\x00\x1e\xdd\x11\x36\x8c\xb4\xdd\x78\x47\xcb\xf0\xb1\x83\x60\xff\xf4\x66\xe9\xce\x4e\xcf\xd2\x7e\xf1\x21\xde\x7e\xcd\x78\xd7\xce\xe4\x5c\x52\xf3\xa2\x76\xa8\xb5\xe8\x46\x30\xa5\xdd\x53\xb0\x7f\x9a\xe1\xa7\xde\x6c\x5c\x53\xc5\xf3\xb5\x1b\xee\xd9\x69\x5f\x4f\xbc\xd6\x90\x39\x28\x8b\xb6\x4d\xfe\x13\x00\x00\xff\xff\x23\xd3\x15\x4c\xca\x16\x00\x00") +var _templateEntTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xa4\x58\x5d\x6f\xe3\xb8\xd5\xbe\xb6\x7e\xc5\x59\xc1\xb3\x6b\x1b\x8e\x34\xef\xde\xbd\xd3\xa6\x40\x76\x92\x01\x02\x0c\xb2\x6d\x93\x41\x2f\x06\x83\x09\x2d\x1e\xd9\x6c\x64\xd2\x43\x52\x4e\x02\x41\xff\xbd\x38\xa4\x28\x53\xb6\x92\x4d\xb7\x57\x96\xc9\xf3\xf9\x1c\xf2\x7c\xb0\x69\xf2\x45\xf2\x51\xed\x9e\xb5\x58\x6f\x2c\xfc\xfa\xfe\xff\xfe\xff\x6c\xa7\xd1\xa0\xb4\xf0\x89\x15\xb8\x52\xea\x01\xae\x65\x91\xc1\x45\x55\x81\x23\x32\x40\xfb\x7a\x8f\x3c\x4b\xee\x36\xc2\x80\x51\xb5\x2e\x10\x0a\xc5\x11\x84\x81\x4a\x14\x28\x0d\x72\xa8\x25\x47\x0d\x76\x83\x70\xb1\x63\xc5\x06\xe1\xd7\xec\x7d\xd8\x85\x52\xd5\x92\x27\x42\xba\xfd\xcf\xd7\x1f\xaf\x6e\x6e\xaf\xa0\x14\x15\x42\xb7\xa6\x95\xb2\xc0\x85\xc6\xc2\x2a\xfd\x0c\xaa\x04\x1b\x29\xb3\x1a\x31\x4b\x16\x79\xdb\x26\x49\xd3\x00\xc7\x52\x48\x84\x74\xab\x38\x56\x29\x74\xab\xd3\xdd\xc3\x1a\x3e\x9c\xc3\x8a\x19\x84\x69\xf6\x51\xc9\x52\xac\xb3\xbf\xb3\xe2\x81\xad\x91\x88\x9a\x06\x2c\x6e\x77\x15\xb3\x08\xe9\x06\x19\x47\x9d\xc2\x34\xb0\x1f\xb6\xc4\x76\xa7\xb4\x0d\x5b\x79\x0e\x24\x3c\xbb\x61\x5b\x92\x42\x3e\x93\xc1\x4e\x37\xa0\xb4\xc2\x3e\x43\xa9\xbc\xe7\x03\x42\x53\x6c\x70\xcb\xb2\xc4\x3e\xef\x8e\x77\xac\xae\x0b\x0b\x4d\x32\x29\x9c\x91\x30\x50\xef\x24\xe7\x6a\x2b\xac\x65\x6b\xd3\x99\x31\xc9\x73\xb8\xbe\xf4\xb8\x20\xa9\xcd\x92\xc9\xf5\xa5\x17\x7b\x7d\x99\xdd\x91\x8e\xb6\x85\xfb\xb0\x70\xeb\x54\xdc\xb1\x35\xb4\xed\x7d\x32\x69\x9a\x33\xd0\x4c\xae\x11\xa6\xdf\x97\x30\x2d\x09\xa7\x69\xf6\x49\x60\xc5\x8d\x13\x3f\xe9\xdc\x2c\x3b\x4e\xb7\x45\x12\x37\x8a\x48\x48\xe9\x9e\x55\x35\x06\x0b\x52\x4f\xdc\x79\x94\x42\x49\xf4\x59\x02\x00\x30\x19\x95\xd3\x34\x20\x4a\xc7\x22\xaa\x8a\xad\x2a\x62\x5b\x34\x0d\xa0\xa4\x6d\xcf\x12\xbc\xf0\xb4\x52\x59\x27\x07\xa5\x11\x56\xec\x69\xe7\x3e\x16\xdd\x39\x47\x32\x2a\x83\x5e\xc8\xeb\x28\xf6\xea\x3c\x20\xf1\xf7\xa3\xb0\x1b\x98\x66\x57\x7c\x8d\x07\x40\xfc\xbf\x03\x02\x1a\x2b\x66\x85\x92\x26\x47\xb7\x43\x61\x57\x76\x83\x1a\xa4\xe2\x68\xc2\x59\x5e\x6b\xb6\xdb\x64\x5e\xc4\x5d\x00\xce\x00\xd3\x08\x2b\x14\x72\x0d\x3b\xb5\xab\xc9\x4a\x0e\xab\xe7\x93\x73\xf3\x8f\x1a\xf5\x33\x3c\x6e\x50\x02\xb2\x35\xea\xb3\x4a\x31\x4e\x5c\x74\x1d\x90\xe2\x3e\xf1\x76\xc5\x4c\x7e\xe5\xfe\xdf\x46\xc9\x0f\xa9\x33\x2e\xbd\x3f\x38\x79\x16\xbc\xcc\x17\x70\xc1\xb9\x20\x1f\x58\xe5\x63\x66\xc0\x2a\x60\xbc\x37\xc5\x58\xa5\xe9\xbe\x70\x2d\xf6\xa8\x33\x70\x97\xce\x31\x4f\xed\x76\x57\xd1\xc1\xd9\x69\x21\x6d\x09\x29\x17\xac\xc2\xc2\xe6\xef\x4c\xee\xd1\xf6\x02\x53\x98\x66\xb7\x9d\x94\xc0\x2b\x4a\xd8\x30\x73\x17\xa2\xe3\x45\x39\x98\x69\xf7\xc9\x0e\x37\xb2\xd1\x10\xbd\xc1\xf8\xda\xc4\x26\x9f\x9c\x06\xcf\x93\xb3\x5e\x4a\x77\xb9\x5c\x02\x38\x3d\x03\x47\x37\xff\x7f\x3b\x0d\x27\x59\xc0\x8b\x3b\xa4\x82\xe8\x8a\x22\xa1\x9c\x0d\xee\x25\xbe\xf1\x5e\x7a\xda\x90\x68\xc8\xb0\xcc\x81\x3c\x22\x21\xba\x65\x98\x7d\x91\xe2\x47\x4d\x3c\x5f\xbf\xf5\xb7\x64\xe1\xd9\xe8\x56\xf6\x12\x9b\xa6\x83\x09\x4f\x6e\x61\x16\x6e\xe3\xc8\x15\xcb\x73\xa0\x63\x8c\x9c\x84\xc5\x20\x0a\x59\x2a\xbd\x75\x38\x3a\x00\x35\x52\xee\x75\xc7\xbd\x04\xe6\x18\x1d\x72\x8f\xcc\x74\x12\x60\xe6\xc8\x7e\xd4\x68\x2c\xf2\x39\xc1\x3c\xbc\x27\x8a\x02\x40\xf7\x24\xd6\xf8\xb5\x69\xa0\x42\xe9\x8c\xfc\xb6\x52\xaa\x0a\x41\xef\x20\x17\xcb\x01\xec\x2f\xa0\xfe\xbb\xbe\xd2\xa4\xdc\xd6\x5a\x9a\x08\xef\x23\x64\xbb\x88\x68\x60\x12\x50\x6b\xa5\xc9\x19\x97\xb7\xf9\x1a\x9d\x70\x72\x87\x90\xef\x5c\x3a\xf6\xa1\x4b\x96\x51\x58\x96\x24\xae\xa3\x5e\xd5\xb6\x17\xe0\x0a\x6b\x0f\x7a\x96\x4c\xca\x5a\x16\x30\x1b\x39\x6a\xf3\x97\x3d\x9a\xcd\x61\xf6\x67\x4e\xc3\xd2\x7b\x37\xa7\xe3\x3b\x11\x25\x60\x16\x41\x4e\x88\x4f\x05\xc1\xed\xb6\x43\x1a\x88\xa5\xd3\xb2\xe7\x1b\x85\xf1\xfc\x1c\xa4\xa8\x3c\x77\x9f\x4c\x09\xc2\xa3\x53\x1e\x9d\x8d\x63\x20\x97\x3d\xef\x09\x68\x99\xdf\xf2\xc1\x24\x45\x4b\xf8\xf9\x46\xd9\x4f\xb4\x77\x45\x6e\x35\x15\x5b\x61\xf5\x01\x22\xbf\x0f\xcd\x44\xf6\x99\x36\xbd\x07\x6d\x70\x2f\x9c\xf6\x5e\xea\xb8\x63\x4b\xd2\x96\x78\xbe\x63\xf5\x9f\x9d\x1f\x5e\x3f\xb9\xfa\xc1\x57\xda\xde\xd9\xb4\x4d\x26\x6d\x12\x29\x8b\x3e\x5d\x13\xe4\x12\xe8\x68\x8e\xe6\x48\x3d\x5b\xae\x24\x1e\x65\xe8\xa6\x39\xc9\xc0\x7d\x57\x34\xd5\x58\x20\x55\x02\xdf\x31\xfc\x33\xfc\xeb\xb6\xa3\x9e\x02\x3d\xc5\xa1\x82\xba\x5a\x4d\xa7\x31\x94\x0c\x48\x5d\x6d\x4b\x4f\x11\xe9\x2f\x9c\xa3\x6f\x5b\xf8\x51\xa3\x16\x68\x5e\x48\x69\x71\xb2\x0b\x1b\xfd\xd1\x1f\x18\xdd\xb6\xb0\x88\xa9\xe6\xb1\x96\xd9\x1c\x8e\x0f\x75\x28\xbf\xcd\x21\x34\xb3\x9f\x63\x01\x1f\x2b\x81\xd2\x36\x70\xa4\x25\xf3\x8d\x5c\x3b\xcf\x62\xf9\x47\x44\x73\x1f\xba\x3e\x5c\x79\x0e\x5f\x76\x9c\x40\x0f\x19\x85\xc1\xaa\x16\x15\xf5\xd1\x94\x0b\x6b\xda\xa4\x8c\xe6\x5a\xe1\xa1\xb3\x79\x0e\x37\xca\x22\xd8\x0d\xb3\x4b\x78\x56\x35\x48\x44\x4e\xe5\xb0\x60\x55\x35\x24\xfe\x22\x1f\x35\xdb\xcd\xe6\xb0\xc2\x52\x69\x74\x14\xbd\xd8\x2d\xda\x8d\xe2\x4b\x9f\xa1\x8e\xd4\x24\x5d\xa6\xf2\xe6\x21\x87\x52\xab\x2d\x30\xb0\x9a\x49\xc3\x0a\x4a\xda\x4b\x60\x92\xbb\x60\x44\x8b\x8e\xa9\x50\x5b\x6a\xbe\x90\x53\xe6\xd2\xaa\xaa\x28\x73\xb1\xe2\x21\x4b\xde\x14\x27\x8f\x4c\x08\x51\x58\xf7\xab\xbf\x4b\xa4\x08\xfd\xb9\x00\xf5\x22\x4e\xc3\xd3\xc5\xc4\xc1\x05\xb5\xfb\x31\xa1\xdf\xa6\x36\x9f\xc0\xfe\x23\x40\x80\x95\x16\x35\x08\x4f\x58\x54\xca\x20\x5f\x92\x58\xa3\x3c\x3f\x85\x47\xe2\x93\xed\xcf\xf8\xa3\xa8\x2a\x58\x21\xe0\x13\x16\x35\xe1\x65\x37\x5a\xd5\xeb\x8d\xd3\xec\xdb\x30\x78\xdc\x88\x62\x03\x85\x46\xe6\x09\x06\x70\xbf\x15\xd1\x70\x0c\x06\xeb\x04\xa4\x7d\x5a\x82\x7a\xa0\x7b\x3a\x8e\x5a\xd6\x35\x83\xb3\x85\x7d\xba\x74\x9f\xf3\x84\xf2\xf6\x4f\xea\xc1\xdd\x94\x1d\x93\xa2\x98\xa5\x61\x06\x6b\xdb\x0f\x27\x23\x13\xa5\xdd\x01\x4e\x2c\x0c\x4f\xa9\xbb\x16\x93\x57\x35\xc3\x39\xd8\xa7\x8c\xeb\x7d\x1f\xf4\x23\xf2\x2e\x74\xb7\x56\xbb\xd6\x61\xbb\xab\x70\x8b\xd2\xfa\xe8\x95\x5b\x9b\xf9\x1d\xd4\x6f\xc4\xca\x93\xcf\xe6\xd4\x9f\x91\xc4\x26\x99\xec\x99\xee\x6f\xa7\x5f\x35\xd9\x6f\xfe\x7f\x32\xe9\x36\xb2\x7f\x69\x61\xb1\x63\x4e\x63\x91\x33\x72\x73\x8c\xca\x19\xe7\xb3\xf5\x2c\x15\xfc\xfc\xdd\x3e\x5d\x9e\x84\xe1\xfa\x72\x3e\x1f\x74\x88\x62\x7c\x88\x0b\x35\x76\x38\x35\x51\x41\x1a\x35\x70\x09\x83\x29\xee\xfc\xaf\x26\x70\xfd\x8d\xcc\xf5\x35\xcd\xcf\x56\xa1\xc4\x4d\x4d\x19\x8f\x00\xef\x4c\xf6\x8e\x1a\xfe\xde\xd8\x93\xc1\x2f\x2e\xfd\x83\xe1\x2f\x14\xff\x7d\x38\x77\xa6\x84\xb6\xfd\x0b\xec\xe1\xa7\x41\xdd\x7f\x93\xe5\xce\xdc\x81\xa6\x6b\x73\x27\xb6\xbd\x9e\x71\x31\xfb\xec\x93\x6b\x3e\x67\x56\x6c\x31\xbb\xb8\xb9\xbd\xfe\x38\x8f\x04\x39\xd7\x83\xb4\xee\x68\xbd\x2a\x6f\xb1\x3f\xe6\x7e\x95\x7c\x10\x7a\x17\xf7\xc5\x7e\xa0\xbf\x6f\x27\xa2\x16\x23\x92\xfa\xdf\x20\xf3\x22\x30\x63\x42\xfa\x68\xbc\x88\xcf\x1f\xc1\xf3\xaa\xd4\x23\x11\xaf\xf1\x9c\x42\x74\x90\x12\x89\x91\xf1\x49\xeb\xff\x1d\x0f\x90\xe1\x7b\xa0\xe8\xb7\x67\x8b\xb3\x5f\xe6\xbf\xcc\xfb\xd4\x12\xb6\x43\x0e\x08\x93\x02\x0d\x24\x92\xfb\xe7\x95\xde\xe1\x99\xeb\x98\x69\xe9\x8b\x41\x7d\xe9\x1e\xa6\xf8\xbc\xab\x9d\x82\x0f\x66\x05\x6a\x81\x34\x76\xef\x6d\x7e\xe4\xe9\x1a\x99\xeb\xcb\xf0\x80\xf2\xa6\xec\x24\xf8\x6c\xee\xa4\x35\xc9\x44\xf0\x25\x7c\xa7\x2b\x64\xac\x2e\x94\xdc\x67\x17\x56\x89\x63\x01\x94\x40\x7a\xff\x04\x4f\x4e\xdb\x46\x53\x89\xc2\x75\x70\xbb\xaa\xd6\xac\x1a\xf6\x00\x07\x02\x9f\xcc\x19\xec\x98\x36\xee\x1e\xfb\x65\x55\x1e\xb5\x27\xfd\xb4\xdb\xb3\x7d\xfd\x36\x70\xc2\x69\x75\x93\x24\x3e\x59\x32\x64\x0a\xe9\x2d\xd1\xa6\x07\x1e\x5f\x14\x5e\x79\x75\xe8\x3a\xda\x2d\x93\xcf\xa7\x8f\x0e\xe3\xaf\x0a\x51\xfb\x35\x0e\x75\x6c\xf4\x1c\x7c\x15\x9a\x15\xe5\xba\xfb\x74\xb3\x0e\x35\x67\xdf\x05\x19\xe5\xd3\xf1\x89\x8c\x6e\xe4\x8e\xd6\xbe\x7e\x17\xdf\xba\x9a\x06\xe7\x50\x94\x6b\x2a\x7a\x03\x73\x9a\x26\x5f\xc0\xc5\xe1\xcd\xc2\x3d\x27\x50\x07\x45\xc7\xcc\x3f\x13\x9c\x59\xb6\x36\xdd\xfb\xc6\xf1\x33\x68\xf4\xd4\xe5\x1e\xba\xba\xc7\x8c\x3b\xb6\xf6\x03\xb0\x9f\xcd\xa3\xf2\x61\xc3\xb4\xdb\x4d\x7e\xb4\x0c\xef\x3b\x08\x0e\xaf\x72\x96\xca\x79\x7a\x96\xf6\x8b\xf7\xf1\xf6\x4b\xc6\xbb\x4e\xa7\x60\x92\xfa\x1a\xb5\x47\xad\x45\x37\x9d\x29\xed\x5e\x89\xfd\xab\x0d\x1b\x7b\xce\x71\xfd\x16\x2b\x36\x6e\xee\xcf\xc6\x7d\x1d\x79\xc8\x21\x73\x50\xf2\xb6\x4d\xfe\x13\x00\x00\xff\xff\xa8\xb8\xde\x24\xe5\x16\x00\x00") func templateEntTmplBytes() ([]byte, error) { return bindataRead( @@ -836,7 +836,7 @@ func templateEntTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/ent.tmpl", size: 5834, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/ent.tmpl", size: 5861, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/dialect/sql/query.tmpl b/entc/gen/template/dialect/sql/query.tmpl index e76e5c67b..d34f605ce 100644 --- a/entc/gen/template/dialect/sql/query.tmpl +++ b/entc/gen/template/dialect/sql/query.tmpl @@ -175,7 +175,7 @@ func ({{ $receiver }} *{{ $builder }}) sqlQuery() *sql.Selector { {{- $n := $ }} {{/* the node we start the query from. */}} {{- $e := $.Scope.Edge }} {{/* the edge we need to genegrate the path to. */}} {{- $receiver := $.Scope.Receiver -}} - id := {{ $receiver }}.{{- if $n.ID.IsString }}id(){{ else }}ID{{ end }} + id := {{ $receiver }}.{{ if and $.ID.IsString (not $.ID.UserDefined) }}id(){{ else }}ID{{ end }} step := sqlgraph.NewStep( sqlgraph.From({{ $n.Package }}.Table, {{ $n.Package }}.{{ $n.ID.Constant }}, id), sqlgraph.To({{ $e.Type.Package }}.Table, {{ $e.Type.Package }}.{{ $e.Type.ID.Constant }}), diff --git a/entc/gen/template/ent.tmpl b/entc/gen/template/ent.tmpl index aa24adc9e..b4487fab0 100644 --- a/entc/gen/template/ent.tmpl +++ b/entc/gen/template/ent.tmpl @@ -133,7 +133,7 @@ func ({{ $receiver }} *{{ $.Name }}) String() string { return builder.String() } -{{- if $.ID.IsString }} +{{- if and $.ID.IsString (not $.ID.UserDefined) }} // id returns the int representation of the ID field. func ({{ $receiver }} *{{ $.Name }}) id() int { id, _ := strconv.Atoi({{ $receiver }}.ID) diff --git a/entc/gen/type.go b/entc/gen/type.go index e8fe385c1..d24f40e6b 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -30,7 +30,6 @@ type ( ID *Field // Fields holds all the primitive fields of this type. Fields []*Field - // fields map for fast lookup. fields map[string]*Field // Edge holds all the edges of this type. Edges []*Edge @@ -38,7 +37,6 @@ type ( Indexes []*Index // ForeignKeys are the foreign-keys that resides in the type table. ForeignKeys []*ForeignKey - // foreignkeys used for first lookup from edge name to foreign-key. foreignkeys map[string]*ForeignKey } @@ -172,7 +170,7 @@ func NewType(c *Config, schema *load.Schema) (*Type, error) { if err := validEnums(f); err != nil { return nil, err } - // enum types should be named as follows: typepkg.Field. + // Enum types should be named as follows: typepkg.Field. f.Info.Ident = fmt.Sprintf("%s.%s", typ.Package(), pascal(f.Name)) } tf := &Field{ @@ -417,11 +415,15 @@ func (t *Type) resolveFKs() { if e.IsInverse() || e.M2M() { continue } + typ := t.ID.Type + if e.OwnFK() { + typ = e.Type.ID.Type + } fk := &ForeignKey{ Edge: e, Field: &Field{ Name: e.Rel.Column(), - Type: e.Type.ID.Type, + Type: typ, Nillable: true, Optional: true, Unique: e.Unique, diff --git a/entc/integration/customid/customid_test.go b/entc/integration/customid/customid_test.go index 808c5348e..ebb3b66aa 100644 --- a/entc/integration/customid/customid_test.go +++ b/entc/integration/customid/customid_test.go @@ -6,33 +6,95 @@ package customid import ( "context" + "database/sql" + "fmt" + "net" + "strconv" "testing" + "github.com/facebookincubator/ent/dialect" "github.com/facebookincubator/ent/entc/integration/customid/ent" + "github.com/facebookincubator/ent/entc/integration/customid/ent/user" + "github.com/go-sql-driver/mysql" + _ "github.com/go-sql-driver/mysql" "github.com/google/uuid" + _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/require" ) -func TestCustomID(t *testing.T) { +func TestMySQL(t *testing.T) { + for version, port := range map[string]int{"56": 3306, "57": 3307, "8": 3308} { + addr := net.JoinHostPort("localhost", strconv.Itoa(port)) + t.Run(version, func(t *testing.T) { + cfg := mysql.Config{ + User: "root", Passwd: "pass", Net: "tcp", Addr: addr, + AllowNativePasswords: true, ParseTime: true, + } + db, err := sql.Open("mysql", cfg.FormatDSN()) + require.NoError(t, err) + defer db.Close() + _, err = db.Exec("CREATE DATABASE IF NOT EXISTS custom_id") + require.NoError(t, err, "creating database") + defer db.Exec("DROP DATABASE IF EXISTS custom_id") + + cfg.DBName = "custom_id" + client, err := ent.Open("mysql", cfg.FormatDSN()) + require.NoError(t, err, "connecting to json database") + err = client.Schema.Create(context.Background()) + require.NoError(t, err) + CustomID(t, client) + }) + } +} + +func TestPostgres(t *testing.T) { + for version, port := range map[string]int{"10": 5430, "11": 5431, "12": 5432} { + t.Run(version, func(t *testing.T) { + dsn := fmt.Sprintf("host=localhost port=%d user=postgres password=pass sslmode=disable", port) + db, err := sql.Open(dialect.Postgres, dsn) + require.NoError(t, err) + defer db.Close() + _, err = db.Exec("CREATE DATABASE custom_id") + require.NoError(t, err, "creating database") + defer db.Exec("DROP DATABASE custom_id") + + client, err := ent.Open(dialect.Postgres, dsn+" dbname=custom_id") + require.NoError(t, err, "connecting to json database") + defer client.Close() + err = client.Schema.Create(context.Background()) + require.NoError(t, err) + CustomID(t, client) + }) + } +} + +func TestSQLite(t *testing.T) { client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") require.NoError(t, err) defer client.Close() - ctx := context.Background() - require.NoError(t, client.Schema.Create(ctx)) + require.NoError(t, client.Schema.Create(context.Background())) + CustomID(t, client) +} +func CustomID(t *testing.T, client *ent.Client) { + ctx := context.Background() nat := client.User.Create().SaveX(ctx) require.Equal(t, 1, nat.ID) - _, err = client.User.Create().SetID(1).Save(ctx) + _, err := client.User.Create().SetID(1).Save(ctx) require.True(t, ent.IsConstraintError(err), "duplicate id") a8m := client.User.Create().SetID(5).SaveX(ctx) require.Equal(t, 5, a8m.ID) hub := client.Group.Create().SetID(3).AddUsers(a8m, nat).SaveX(ctx) require.Equal(t, 3, hub.ID) - require.Equal(t, []int{1, 5}, hub.QueryUsers().IDsX(ctx)) + require.Equal(t, []int{1, 5}, hub.QueryUsers().Order(ent.Asc(user.FieldID)).IDsX(ctx)) b := client.Blob.Create().SetID(uuid.New()).SaveX(ctx) require.NotEmpty(t, b.ID) + + pedro := client.Pet.Create().SetID("pedro").SetOwner(a8m).SaveX(ctx) + require.Equal(t, a8m.ID, pedro.QueryOwner().OnlyXID(ctx)) + require.Equal(t, pedro.ID, a8m.QueryPets().OnlyXID(ctx)) } diff --git a/entc/integration/customid/ent/client.go b/entc/integration/customid/ent/client.go index 9398f443c..ef474817a 100644 --- a/entc/integration/customid/ent/client.go +++ b/entc/integration/customid/ent/client.go @@ -321,6 +321,20 @@ func (c *PetClient) GetX(ctx context.Context, id string) *Pet { return pe } +// QueryOwner queries the owner edge of a Pet. +func (c *PetClient) QueryOwner(pe *Pet) *UserQuery { + query := &UserQuery{config: c.config} + id := pe.ID + step := sqlgraph.NewStep( + sqlgraph.From(pet.Table, pet.FieldID, id), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, pet.OwnerTable, pet.OwnerColumn), + ) + query.sql = sqlgraph.Neighbors(pe.driver.Dialect(), step) + + return query +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -426,3 +440,17 @@ func (c *UserClient) QueryChildren(u *User) *UserQuery { return query } + +// QueryPets queries the pets edge of a User. +func (c *UserClient) QueryPets(u *User) *PetQuery { + query := &PetQuery{config: c.config} + id := u.ID + step := sqlgraph.NewStep( + sqlgraph.From(user.Table, user.FieldID, id), + sqlgraph.To(pet.Table, pet.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.PetsTable, user.PetsColumn), + ) + query.sql = sqlgraph.Neighbors(u.driver.Dialect(), step) + + return query +} diff --git a/entc/integration/customid/ent/example_test.go b/entc/integration/customid/ent/example_test.go index d6c77f93a..faff31530 100644 --- a/entc/integration/customid/ent/example_test.go +++ b/entc/integration/customid/ent/example_test.go @@ -116,11 +116,16 @@ func ExampleUser() { Create(). SaveX(ctx) log.Println("user created:", u2) + pe3 := client.Pet. + Create(). + SaveX(ctx) + log.Println("pet created:", pe3) // create user vertex with its edges. u := client.User. Create(). AddChildren(u2). + AddPets(pe3). SaveX(ctx) log.Println("user created:", u) @@ -132,5 +137,11 @@ func ExampleUser() { } log.Println("children found:", u2) + pe3, err = u.QueryPets().First(ctx) + if err != nil { + log.Fatalf("failed querying pets: %v", err) + } + log.Println("pets found:", pe3) + // Output: } diff --git a/entc/integration/customid/ent/migrate/schema.go b/entc/integration/customid/ent/migrate/schema.go index 6650bfbcc..95367c228 100644 --- a/entc/integration/customid/ent/migrate/schema.go +++ b/entc/integration/customid/ent/migrate/schema.go @@ -40,13 +40,22 @@ var ( // PetsColumns holds the columns for the "pets" table. PetsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true, Size: 25}, + {Name: "user_pets", Type: field.TypeInt, Nullable: true}, } // PetsTable holds the schema information for the "pets" table. PetsTable = &schema.Table{ - Name: "pets", - Columns: PetsColumns, - PrimaryKey: []*schema.Column{PetsColumns[0]}, - ForeignKeys: []*schema.ForeignKey{}, + Name: "pets", + Columns: PetsColumns, + PrimaryKey: []*schema.Column{PetsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "pets_users_pets", + Columns: []*schema.Column{PetsColumns[1]}, + + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.SetNull, + }, + }, } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ @@ -106,6 +115,7 @@ var ( ) func init() { + PetsTable.ForeignKeys[0].RefTable = UsersTable UsersTable.ForeignKeys[0].RefTable = UsersTable GroupUsersTable.ForeignKeys[0].RefTable = GroupsTable GroupUsersTable.ForeignKeys[1].RefTable = UsersTable diff --git a/entc/integration/customid/ent/pet.go b/entc/integration/customid/ent/pet.go index 9f10281a6..ec91feaa7 100644 --- a/entc/integration/customid/ent/pet.go +++ b/entc/integration/customid/ent/pet.go @@ -8,11 +8,11 @@ package ent import ( "fmt" - "strconv" "strings" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/customid/ent/pet" + "github.com/facebookincubator/ent/entc/integration/customid/ent/user" ) // Pet is the model entity for the Pet schema. @@ -20,6 +20,33 @@ type Pet struct { config // ID of the ent. ID string `json:"id,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the PetQuery when eager-loading is set. + Edges PetEdges `json:"edges"` + user_pets *int +} + +// PetEdges holds the relations/edges for other nodes in the graph. +type PetEdges struct { + // Owner holds the value of the owner edge. + Owner *User + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// OwnerOrErr returns the Owner value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e PetEdges) OwnerOrErr() (*User, error) { + if e.loadedTypes[0] { + if e.Owner == nil { + // The edge owner was loaded in eager-loading, + // but was not found. + return nil, &NotFoundError{label: user.Label} + } + return e.Owner, nil + } + return nil, &NotLoadedError{edge: "owner"} } // scanValues returns the types for scanning values from sql.Rows. @@ -29,6 +56,13 @@ func (*Pet) scanValues() []interface{} { } } +// fkValues returns the types for scanning foreign-keys values from sql.Rows. +func (*Pet) fkValues() []interface{} { + return []interface{}{ + &sql.NullInt64{}, // user_pets + } +} + // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the Pet fields. func (pe *Pet) assignValues(values ...interface{}) error { @@ -41,9 +75,23 @@ func (pe *Pet) assignValues(values ...interface{}) error { pe.ID = value.String } values = values[1:] + values = values[0:] + if len(values) == len(pet.ForeignKeys) { + if value, ok := values[0].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for edge-field user_pets", value) + } else if value.Valid { + pe.user_pets = new(int) + *pe.user_pets = int(value.Int64) + } + } return nil } +// QueryOwner queries the owner edge of the Pet. +func (pe *Pet) QueryOwner() *UserQuery { + return (&PetClient{pe.config}).QueryOwner(pe) +} + // Update returns a builder for updating this Pet. // Note that, you need to call Pet.Unwrap() before calling this method, if this Pet // was returned from a transaction, and the transaction was committed or rolled back. @@ -71,12 +119,6 @@ func (pe *Pet) String() string { return builder.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/customid/ent/pet/pet.go b/entc/integration/customid/ent/pet/pet.go index d63ea09ec..457c70ed1 100644 --- a/entc/integration/customid/ent/pet/pet.go +++ b/entc/integration/customid/ent/pet/pet.go @@ -14,9 +14,21 @@ const ( // Table holds the table name of the pet in the database. Table = "pets" + // OwnerTable is the table the holds the owner relation/edge. + OwnerTable = "pets" + // OwnerInverseTable is the table name for the User entity. + // It exists in this package in order to avoid circular dependency with the "user" package. + OwnerInverseTable = "users" + // OwnerColumn is the table column denoting the owner relation/edge. + OwnerColumn = "user_pets" ) // Columns holds all SQL columns for pet fields. var Columns = []string{ FieldID, } + +// ForeignKeys holds the SQL foreign-keys that are owned by the Pet type. +var ForeignKeys = []string{ + "user_pets", +} diff --git a/entc/integration/customid/ent/pet/where.go b/entc/integration/customid/ent/pet/where.go index 711ed33e3..007c8eb95 100644 --- a/entc/integration/customid/ent/pet/where.go +++ b/entc/integration/customid/ent/pet/where.go @@ -8,6 +8,7 @@ package pet import ( "github.com/facebookincubator/ent/dialect/sql" + "github.com/facebookincubator/ent/dialect/sql/sqlgraph" "github.com/facebookincubator/ent/entc/integration/customid/ent/predicate" ) @@ -94,6 +95,34 @@ func IDLTE(id string) predicate.Pet { }) } +// HasOwner applies the HasEdge predicate on the "owner" edge. +func HasOwner() predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(OwnerTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates). +func HasOwnerWith(preds ...predicate.User) predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(OwnerInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups list of predicates with the AND operator between them. func And(predicates ...predicate.Pet) predicate.Pet { return predicate.Pet(func(s *sql.Selector) { diff --git a/entc/integration/customid/ent/pet_create.go b/entc/integration/customid/ent/pet_create.go index 781e66be6..f99e60be3 100644 --- a/entc/integration/customid/ent/pet_create.go +++ b/entc/integration/customid/ent/pet_create.go @@ -8,16 +8,19 @@ package ent import ( "context" + "errors" "github.com/facebookincubator/ent/dialect/sql/sqlgraph" "github.com/facebookincubator/ent/entc/integration/customid/ent/pet" + "github.com/facebookincubator/ent/entc/integration/customid/ent/user" "github.com/facebookincubator/ent/schema/field" ) // PetCreate is the builder for creating a Pet entity. type PetCreate struct { config - id *string + id *string + owner map[int]struct{} } // SetID sets the id field. @@ -26,8 +29,33 @@ func (pc *PetCreate) SetID(s string) *PetCreate { return pc } +// SetOwnerID sets the owner edge to User by id. +func (pc *PetCreate) SetOwnerID(id int) *PetCreate { + if pc.owner == nil { + pc.owner = make(map[int]struct{}) + } + pc.owner[id] = struct{}{} + return pc +} + +// SetNillableOwnerID sets the owner edge to User by id if the given value is not nil. +func (pc *PetCreate) SetNillableOwnerID(id *int) *PetCreate { + if id != nil { + pc = pc.SetOwnerID(*id) + } + return pc +} + +// SetOwner sets the owner edge to User. +func (pc *PetCreate) SetOwner(u *User) *PetCreate { + return pc.SetOwnerID(u.ID) +} + // Save creates the Pet in the database. func (pc *PetCreate) Save(ctx context.Context) (*Pet, error) { + if len(pc.owner) > 1 { + return nil, errors.New("ent: multiple assignments on a unique edge \"owner\"") + } return pc.sqlSave(ctx) } @@ -55,6 +83,25 @@ func (pc *PetCreate) sqlSave(ctx context.Context) (*Pet, error) { pe.ID = *value _spec.ID.Value = *value } + if nodes := pc.owner; len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: pet.OwnerTable, + Columns: []string{pet.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + for k, _ := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if err := sqlgraph.CreateNode(ctx, pc.driver, _spec); err != nil { if cerr, ok := isSQLConstraintError(err); ok { err = cerr diff --git a/entc/integration/customid/ent/pet_query.go b/entc/integration/customid/ent/pet_query.go index 7cb997db8..635fc0a62 100644 --- a/entc/integration/customid/ent/pet_query.go +++ b/entc/integration/customid/ent/pet_query.go @@ -16,6 +16,7 @@ import ( "github.com/facebookincubator/ent/dialect/sql/sqlgraph" "github.com/facebookincubator/ent/entc/integration/customid/ent/pet" "github.com/facebookincubator/ent/entc/integration/customid/ent/predicate" + "github.com/facebookincubator/ent/entc/integration/customid/ent/user" "github.com/facebookincubator/ent/schema/field" ) @@ -27,6 +28,9 @@ type PetQuery struct { order []Order unique []string predicates []predicate.Pet + // eager-loading edges. + withOwner *UserQuery + withFKs bool // intermediate query. sql *sql.Selector } @@ -55,6 +59,18 @@ func (pq *PetQuery) Order(o ...Order) *PetQuery { return pq } +// QueryOwner chains the current query on the owner edge. +func (pq *PetQuery) QueryOwner() *UserQuery { + query := &UserQuery{config: pq.config} + step := sqlgraph.NewStep( + sqlgraph.From(pet.Table, pet.FieldID, pq.sqlQuery()), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, pet.OwnerTable, pet.OwnerColumn), + ) + query.sql = sqlgraph.SetNeighbors(pq.driver.Dialect(), step) + return query +} + // First returns the first Pet entity in the query. Returns *NotFoundError when no pet was found. func (pq *PetQuery) First(ctx context.Context) (*Pet, error) { pes, err := pq.Limit(1).All(ctx) @@ -224,6 +240,17 @@ func (pq *PetQuery) Clone() *PetQuery { } } +// WithOwner tells the query-builder to eager-loads the nodes that are connected to +// the "owner" edge. The optional arguments used to configure the query builder of the edge. +func (pq *PetQuery) WithOwner(opts ...func(*UserQuery)) *PetQuery { + query := &UserQuery{config: pq.config} + for _, opt := range opts { + opt(query) + } + pq.withOwner = query + return pq +} + // GroupBy used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. func (pq *PetQuery) GroupBy(field string, fields ...string) *PetGroupBy { @@ -243,13 +270,26 @@ func (pq *PetQuery) Select(field string, fields ...string) *PetSelect { func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) { var ( - nodes = []*Pet{} - _spec = pq.querySpec() + nodes = []*Pet{} + withFKs = pq.withFKs + _spec = pq.querySpec() + loadedTypes = [1]bool{ + pq.withOwner != nil, + } ) + if pq.withOwner != nil { + withFKs = true + } + if withFKs { + _spec.Node.Columns = append(_spec.Node.Columns, pet.ForeignKeys...) + } _spec.ScanValues = func() []interface{} { node := &Pet{config: pq.config} nodes = append(nodes, node) values := node.scanValues() + if withFKs { + values = append(values, node.fkValues()...) + } return values } _spec.Assign = func(values ...interface{}) error { @@ -257,6 +297,7 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) { return fmt.Errorf("ent: Assign called without calling ScanValues") } node := nodes[len(nodes)-1] + node.Edges.loadedTypes = loadedTypes return node.assignValues(values...) } if err := sqlgraph.QueryNodes(ctx, pq.driver, _spec); err != nil { @@ -265,6 +306,32 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) { if len(nodes) == 0 { return nodes, nil } + + if query := pq.withOwner; query != nil { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*Pet) + for i := range nodes { + if fk := nodes[i].user_pets; fk != nil { + ids = append(ids, *fk) + nodeids[*fk] = append(nodeids[*fk], nodes[i]) + } + } + query.Where(user.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "user_pets" returned %v`, n.ID) + } + for i := range nodes { + nodes[i].Edges.Owner = n + } + } + } + return nodes, nil } diff --git a/entc/integration/customid/ent/pet_update.go b/entc/integration/customid/ent/pet_update.go index 192a16d3e..5929a36c8 100644 --- a/entc/integration/customid/ent/pet_update.go +++ b/entc/integration/customid/ent/pet_update.go @@ -8,18 +8,22 @@ package ent import ( "context" + "errors" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/dialect/sql/sqlgraph" "github.com/facebookincubator/ent/entc/integration/customid/ent/pet" "github.com/facebookincubator/ent/entc/integration/customid/ent/predicate" + "github.com/facebookincubator/ent/entc/integration/customid/ent/user" "github.com/facebookincubator/ent/schema/field" ) // PetUpdate is the builder for updating Pet entities. type PetUpdate struct { config - predicates []predicate.Pet + owner map[int]struct{} + clearedOwner bool + predicates []predicate.Pet } // Where adds a new predicate for the builder. @@ -28,8 +32,39 @@ func (pu *PetUpdate) Where(ps ...predicate.Pet) *PetUpdate { return pu } +// SetOwnerID sets the owner edge to User by id. +func (pu *PetUpdate) SetOwnerID(id int) *PetUpdate { + if pu.owner == nil { + pu.owner = make(map[int]struct{}) + } + pu.owner[id] = struct{}{} + return pu +} + +// SetNillableOwnerID sets the owner edge to User by id if the given value is not nil. +func (pu *PetUpdate) SetNillableOwnerID(id *int) *PetUpdate { + if id != nil { + pu = pu.SetOwnerID(*id) + } + return pu +} + +// SetOwner sets the owner edge to User. +func (pu *PetUpdate) SetOwner(u *User) *PetUpdate { + return pu.SetOwnerID(u.ID) +} + +// ClearOwner clears the owner edge to User. +func (pu *PetUpdate) ClearOwner() *PetUpdate { + pu.clearedOwner = true + return pu +} + // Save executes the query and returns the number of rows/vertices matched by this operation. func (pu *PetUpdate) Save(ctx context.Context) (int, error) { + if len(pu.owner) > 1 { + return 0, errors.New("ent: multiple assignments on a unique edge \"owner\"") + } return pu.sqlSave(ctx) } @@ -73,6 +108,41 @@ func (pu *PetUpdate) sqlSave(ctx context.Context) (n int, err error) { } } } + if pu.clearedOwner { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: pet.OwnerTable, + Columns: []string{pet.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := pu.owner; len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: pet.OwnerTable, + Columns: []string{pet.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + for k, _ := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if n, err = sqlgraph.UpdateNodes(ctx, pu.driver, _spec); err != nil { if cerr, ok := isSQLConstraintError(err); ok { err = cerr @@ -85,11 +155,44 @@ 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 string + owner map[int]struct{} + clearedOwner bool +} + +// SetOwnerID sets the owner edge to User by id. +func (puo *PetUpdateOne) SetOwnerID(id int) *PetUpdateOne { + if puo.owner == nil { + puo.owner = make(map[int]struct{}) + } + puo.owner[id] = struct{}{} + return puo +} + +// SetNillableOwnerID sets the owner edge to User by id if the given value is not nil. +func (puo *PetUpdateOne) SetNillableOwnerID(id *int) *PetUpdateOne { + if id != nil { + puo = puo.SetOwnerID(*id) + } + return puo +} + +// SetOwner sets the owner edge to User. +func (puo *PetUpdateOne) SetOwner(u *User) *PetUpdateOne { + return puo.SetOwnerID(u.ID) +} + +// ClearOwner clears the owner edge to User. +func (puo *PetUpdateOne) ClearOwner() *PetUpdateOne { + puo.clearedOwner = true + return puo } // Save executes the query and returns the updated entity. func (puo *PetUpdateOne) Save(ctx context.Context) (*Pet, error) { + if len(puo.owner) > 1 { + return nil, errors.New("ent: multiple assignments on a unique edge \"owner\"") + } return puo.sqlSave(ctx) } @@ -127,6 +230,41 @@ func (puo *PetUpdateOne) sqlSave(ctx context.Context) (pe *Pet, err error) { }, }, } + if puo.clearedOwner { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: pet.OwnerTable, + Columns: []string{pet.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := puo.owner; len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: pet.OwnerTable, + Columns: []string{pet.OwnerColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: user.FieldID, + }, + }, + } + for k, _ := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } pe = &Pet{config: puo.config} _spec.Assign = pe.assignValues _spec.ScanValues = pe.scanValues() diff --git a/entc/integration/customid/ent/schema/pet.go b/entc/integration/customid/ent/schema/pet.go index df214ffbc..0ab36bcbe 100644 --- a/entc/integration/customid/ent/schema/pet.go +++ b/entc/integration/customid/ent/schema/pet.go @@ -6,6 +6,7 @@ package schema import ( "github.com/facebookincubator/ent" + "github.com/facebookincubator/ent/schema/edge" "github.com/facebookincubator/ent/schema/field" ) @@ -24,3 +25,12 @@ func (Pet) Fields() []ent.Field { Immutable(), } } + +// Edges of the Pet. +func (Pet) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("owner", User.Type). + Ref("pets"). + Unique(), + } +} diff --git a/entc/integration/customid/ent/schema/user.go b/entc/integration/customid/ent/schema/user.go index 19ba8e6ca..7fc618820 100644 --- a/entc/integration/customid/ent/schema/user.go +++ b/entc/integration/customid/ent/schema/user.go @@ -30,5 +30,6 @@ func (User) Edges() []ent.Edge { edge.To("children", User.Type). From("parent"). Unique(), + edge.To("pets", Pet.Type), } } diff --git a/entc/integration/customid/ent/user.go b/entc/integration/customid/ent/user.go index 37b823716..c6a5e20d4 100644 --- a/entc/integration/customid/ent/user.go +++ b/entc/integration/customid/ent/user.go @@ -33,9 +33,11 @@ type UserEdges struct { Parent *User // Children holds the value of the children edge. Children []*User + // Pets holds the value of the pets edge. + Pets []*Pet // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [3]bool + loadedTypes [4]bool } // GroupsOrErr returns the Groups value or an error if the edge @@ -70,6 +72,15 @@ func (e UserEdges) ChildrenOrErr() ([]*User, error) { return nil, &NotLoadedError{edge: "children"} } +// PetsOrErr returns the Pets value or an error if the edge +// was not loaded in eager-loading. +func (e UserEdges) PetsOrErr() ([]*Pet, error) { + if e.loadedTypes[3] { + return e.Pets, nil + } + return nil, &NotLoadedError{edge: "pets"} +} + // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -123,6 +134,11 @@ func (u *User) QueryChildren() *UserQuery { return (&UserClient{u.config}).QueryChildren(u) } +// QueryPets queries the pets edge of the User. +func (u *User) QueryPets() *PetQuery { + return (&UserClient{u.config}).QueryPets(u) +} + // Update returns a builder for updating this User. // Note that, you need to call User.Unwrap() before calling this method, if this User // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/entc/integration/customid/ent/user/user.go b/entc/integration/customid/ent/user/user.go index 65c9d84eb..a22c8918e 100644 --- a/entc/integration/customid/ent/user/user.go +++ b/entc/integration/customid/ent/user/user.go @@ -27,6 +27,13 @@ const ( ChildrenTable = "users" // ChildrenColumn is the table column denoting the children relation/edge. ChildrenColumn = "user_children" + // PetsTable is the table the holds the pets relation/edge. + PetsTable = "pets" + // PetsInverseTable is the table name for the Pet entity. + // It exists in this package in order to avoid circular dependency with the "pet" package. + PetsInverseTable = "pets" + // PetsColumn is the table column denoting the pets relation/edge. + PetsColumn = "user_pets" ) // Columns holds all SQL columns for user fields. diff --git a/entc/integration/customid/ent/user/where.go b/entc/integration/customid/ent/user/where.go index 75d72c562..5794e059b 100644 --- a/entc/integration/customid/ent/user/where.go +++ b/entc/integration/customid/ent/user/where.go @@ -179,6 +179,34 @@ func HasChildrenWith(preds ...predicate.User) predicate.User { }) } +// HasPets applies the HasEdge predicate on the "pets" edge. +func HasPets() predicate.User { + return predicate.User(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(PetsTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, PetsTable, PetsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasPetsWith applies the HasEdge predicate on the "pets" edge with a given conditions (other predicates). +func HasPetsWith(preds ...predicate.Pet) predicate.User { + return predicate.User(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(PetsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, PetsTable, PetsColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // And groups list of predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { return predicate.User(func(s *sql.Selector) { diff --git a/entc/integration/customid/ent/user_create.go b/entc/integration/customid/ent/user_create.go index 692eff473..8272b855f 100644 --- a/entc/integration/customid/ent/user_create.go +++ b/entc/integration/customid/ent/user_create.go @@ -12,6 +12,7 @@ import ( "github.com/facebookincubator/ent/dialect/sql/sqlgraph" "github.com/facebookincubator/ent/entc/integration/customid/ent/group" + "github.com/facebookincubator/ent/entc/integration/customid/ent/pet" "github.com/facebookincubator/ent/entc/integration/customid/ent/user" "github.com/facebookincubator/ent/schema/field" ) @@ -23,6 +24,7 @@ type UserCreate struct { groups map[int]struct{} parent map[int]struct{} children map[int]struct{} + pets map[string]struct{} } // SetID sets the id field. @@ -93,6 +95,26 @@ func (uc *UserCreate) AddChildren(u ...*User) *UserCreate { return uc.AddChildIDs(ids...) } +// AddPetIDs adds the pets edge to Pet by ids. +func (uc *UserCreate) AddPetIDs(ids ...string) *UserCreate { + if uc.pets == nil { + uc.pets = make(map[string]struct{}) + } + for i := range ids { + uc.pets[ids[i]] = struct{}{} + } + return uc +} + +// AddPets adds the pets edges to Pet. +func (uc *UserCreate) AddPets(p ...*Pet) *UserCreate { + ids := make([]string, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return uc.AddPetIDs(ids...) +} + // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { if len(uc.parent) > 1 { @@ -182,6 +204,25 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := uc.pets; len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.PetsTable, + Columns: []string{user.PetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: pet.FieldID, + }, + }, + } + for k, _ := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil { if cerr, ok := isSQLConstraintError(err); ok { err = cerr diff --git a/entc/integration/customid/ent/user_query.go b/entc/integration/customid/ent/user_query.go index a3bc181f7..dc5c2d71a 100644 --- a/entc/integration/customid/ent/user_query.go +++ b/entc/integration/customid/ent/user_query.go @@ -16,6 +16,7 @@ import ( "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/dialect/sql/sqlgraph" "github.com/facebookincubator/ent/entc/integration/customid/ent/group" + "github.com/facebookincubator/ent/entc/integration/customid/ent/pet" "github.com/facebookincubator/ent/entc/integration/customid/ent/predicate" "github.com/facebookincubator/ent/entc/integration/customid/ent/user" "github.com/facebookincubator/ent/schema/field" @@ -33,6 +34,7 @@ type UserQuery struct { withGroups *GroupQuery withParent *UserQuery withChildren *UserQuery + withPets *PetQuery withFKs bool // intermediate query. sql *sql.Selector @@ -98,6 +100,18 @@ func (uq *UserQuery) QueryChildren() *UserQuery { return query } +// QueryPets chains the current query on the pets edge. +func (uq *UserQuery) QueryPets() *PetQuery { + query := &PetQuery{config: uq.config} + step := sqlgraph.NewStep( + sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()), + sqlgraph.To(pet.Table, pet.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.PetsTable, user.PetsColumn), + ) + query.sql = sqlgraph.SetNeighbors(uq.driver.Dialect(), step) + return query +} + // First returns the first User entity in the query. Returns *NotFoundError when no user was found. func (uq *UserQuery) First(ctx context.Context) (*User, error) { us, err := uq.Limit(1).All(ctx) @@ -300,6 +314,17 @@ func (uq *UserQuery) WithChildren(opts ...func(*UserQuery)) *UserQuery { return uq } +// WithPets tells the query-builder to eager-loads the nodes that are connected to +// the "pets" edge. The optional arguments used to configure the query builder of the edge. +func (uq *UserQuery) WithPets(opts ...func(*PetQuery)) *UserQuery { + query := &PetQuery{config: uq.config} + for _, opt := range opts { + opt(query) + } + uq.withPets = query + return uq +} + // GroupBy used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { @@ -322,10 +347,11 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { nodes = []*User{} withFKs = uq.withFKs _spec = uq.querySpec() - loadedTypes = [3]bool{ + loadedTypes = [4]bool{ uq.withGroups != nil, uq.withParent != nil, uq.withChildren != nil, + uq.withPets != nil, } ) if uq.withParent != nil { @@ -474,6 +500,34 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { } } + if query := uq.withPets; query != nil { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*User) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + } + query.withFKs = true + query.Where(predicate.Pet(func(s *sql.Selector) { + s.Where(sql.InValues(user.PetsColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + fk := n.user_pets + if fk == nil { + return nil, fmt.Errorf(`foreign-key "user_pets" is nil for node %v`, n.ID) + } + node, ok := nodeids[*fk] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "user_pets" returned %v for node %v`, *fk, n.ID) + } + node.Edges.Pets = append(node.Edges.Pets, n) + } + } + return nodes, nil } diff --git a/entc/integration/customid/ent/user_update.go b/entc/integration/customid/ent/user_update.go index d9c6f3f43..a89422f75 100644 --- a/entc/integration/customid/ent/user_update.go +++ b/entc/integration/customid/ent/user_update.go @@ -13,6 +13,7 @@ import ( "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/dialect/sql/sqlgraph" "github.com/facebookincubator/ent/entc/integration/customid/ent/group" + "github.com/facebookincubator/ent/entc/integration/customid/ent/pet" "github.com/facebookincubator/ent/entc/integration/customid/ent/predicate" "github.com/facebookincubator/ent/entc/integration/customid/ent/user" "github.com/facebookincubator/ent/schema/field" @@ -24,9 +25,11 @@ type UserUpdate struct { groups map[int]struct{} parent map[int]struct{} children map[int]struct{} + pets map[string]struct{} removedGroups map[int]struct{} clearedParent bool removedChildren map[int]struct{} + removedPets map[string]struct{} predicates []predicate.User } @@ -98,6 +101,26 @@ func (uu *UserUpdate) AddChildren(u ...*User) *UserUpdate { return uu.AddChildIDs(ids...) } +// AddPetIDs adds the pets edge to Pet by ids. +func (uu *UserUpdate) AddPetIDs(ids ...string) *UserUpdate { + if uu.pets == nil { + uu.pets = make(map[string]struct{}) + } + for i := range ids { + uu.pets[ids[i]] = struct{}{} + } + return uu +} + +// AddPets adds the pets edges to Pet. +func (uu *UserUpdate) AddPets(p ...*Pet) *UserUpdate { + ids := make([]string, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return uu.AddPetIDs(ids...) +} + // RemoveGroupIDs removes the groups edge to Group by ids. func (uu *UserUpdate) RemoveGroupIDs(ids ...int) *UserUpdate { if uu.removedGroups == nil { @@ -144,6 +167,26 @@ func (uu *UserUpdate) RemoveChildren(u ...*User) *UserUpdate { return uu.RemoveChildIDs(ids...) } +// RemovePetIDs removes the pets edge to Pet by ids. +func (uu *UserUpdate) RemovePetIDs(ids ...string) *UserUpdate { + if uu.removedPets == nil { + uu.removedPets = make(map[string]struct{}) + } + for i := range ids { + uu.removedPets[ids[i]] = struct{}{} + } + return uu +} + +// RemovePets removes pets edges to Pet. +func (uu *UserUpdate) RemovePets(p ...*Pet) *UserUpdate { + ids := make([]string, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return uu.RemovePetIDs(ids...) +} + // Save executes the query and returns the number of rows/vertices matched by this operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { if len(uu.parent) > 1 { @@ -303,6 +346,44 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if nodes := uu.removedPets; len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.PetsTable, + Columns: []string{user.PetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: pet.FieldID, + }, + }, + } + for k, _ := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := uu.pets; len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.PetsTable, + Columns: []string{user.PetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: pet.FieldID, + }, + }, + } + for k, _ := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil { if cerr, ok := isSQLConstraintError(err); ok { err = cerr @@ -319,9 +400,11 @@ type UserUpdateOne struct { groups map[int]struct{} parent map[int]struct{} children map[int]struct{} + pets map[string]struct{} removedGroups map[int]struct{} clearedParent bool removedChildren map[int]struct{} + removedPets map[string]struct{} } // AddGroupIDs adds the groups edge to Group by ids. @@ -386,6 +469,26 @@ func (uuo *UserUpdateOne) AddChildren(u ...*User) *UserUpdateOne { return uuo.AddChildIDs(ids...) } +// AddPetIDs adds the pets edge to Pet by ids. +func (uuo *UserUpdateOne) AddPetIDs(ids ...string) *UserUpdateOne { + if uuo.pets == nil { + uuo.pets = make(map[string]struct{}) + } + for i := range ids { + uuo.pets[ids[i]] = struct{}{} + } + return uuo +} + +// AddPets adds the pets edges to Pet. +func (uuo *UserUpdateOne) AddPets(p ...*Pet) *UserUpdateOne { + ids := make([]string, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return uuo.AddPetIDs(ids...) +} + // RemoveGroupIDs removes the groups edge to Group by ids. func (uuo *UserUpdateOne) RemoveGroupIDs(ids ...int) *UserUpdateOne { if uuo.removedGroups == nil { @@ -432,6 +535,26 @@ func (uuo *UserUpdateOne) RemoveChildren(u ...*User) *UserUpdateOne { return uuo.RemoveChildIDs(ids...) } +// RemovePetIDs removes the pets edge to Pet by ids. +func (uuo *UserUpdateOne) RemovePetIDs(ids ...string) *UserUpdateOne { + if uuo.removedPets == nil { + uuo.removedPets = make(map[string]struct{}) + } + for i := range ids { + uuo.removedPets[ids[i]] = struct{}{} + } + return uuo +} + +// RemovePets removes pets edges to Pet. +func (uuo *UserUpdateOne) RemovePets(p ...*Pet) *UserUpdateOne { + ids := make([]string, len(p)) + for i := range p { + ids[i] = p[i].ID + } + return uuo.RemovePetIDs(ids...) +} + // Save executes the query and returns the updated entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { if len(uuo.parent) > 1 { @@ -585,6 +708,44 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if nodes := uuo.removedPets; len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.PetsTable, + Columns: []string{user.PetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: pet.FieldID, + }, + }, + } + for k, _ := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := uuo.pets; len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: user.PetsTable, + Columns: []string{user.PetsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: pet.FieldID, + }, + }, + } + for k, _ := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } u = &User{config: uuo.config} _spec.Assign = u.assignValues _spec.ScanValues = u.scanValues() diff --git a/entc/integration/idtype/idtype_test.go b/entc/integration/idtype/idtype_test.go index 5de0cfc92..0d663bc76 100644 --- a/entc/integration/idtype/idtype_test.go +++ b/entc/integration/idtype/idtype_test.go @@ -11,6 +11,7 @@ import ( "github.com/facebookincubator/ent/entc/integration/idtype/ent" "github.com/facebookincubator/ent/entc/integration/idtype/ent/migrate" "github.com/facebookincubator/ent/entc/integration/idtype/ent/user" + _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/require" ) diff --git a/entc/load/load.go b/entc/load/load.go index 185b559ed..d511c7a92 100644 --- a/entc/load/load.go +++ b/entc/load/load.go @@ -139,7 +139,7 @@ var buildTmpl = templates() func templates() *template.Template { tmpl := template.New("templates").Funcs(template.FuncMap{"base": filepath.Base}) tmpl = template.Must(tmpl.Parse(string(internal.MustAsset("template/main.tmpl")))) - // turns the schema file and its imports into templates. + // Turns the schema file and its imports into templates. tmpls, err := schemaTemplates() if err != nil { panic(err)