diff --git a/entc/cmd/entc/entc.go b/entc/cmd/entc/entc.go index 0365f7afe..eaa20e2a5 100644 --- a/entc/cmd/entc/entc.go +++ b/entc/cmd/entc/entc.go @@ -194,6 +194,12 @@ func (t *idType) Set(s string) error { switch s { case field.TypeInt.String(): *t = idType(field.TypeInt) + case field.TypeInt64.String(): + *t = idType(field.TypeInt64) + case field.TypeUint.String(): + *t = idType(field.TypeUint) + case field.TypeUint64.String(): + *t = idType(field.TypeUint64) case field.TypeString.String(): *t = idType(field.TypeString) default: @@ -204,7 +210,13 @@ func (t *idType) Set(s string) error { // 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) + return fmt.Sprintf("%v", []field.Type{ + field.TypeInt, + field.TypeInt64, + field.TypeUint, + field.TypeUint64, + field.TypeString, + }) } // String returns the default value for the help command. diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index f3545ba36..97b64735b 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -537,7 +537,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\xb6\x1a\xbe\x96\x7e\xc5\x7b\x02\xb7\x90\x02\x87\x49\x73\x77\xd2\x93\x03\x64\xf9\x00\xbc\x35\x49\x1b\xa7\xdb\x45\x5b\x0c\xb4\xf4\xd2\xe6\x42\x93\x0e\x49\xb9\x09\x0c\xfd\xf7\x81\x94\x64\xc9\x8a\xf2\xe5\x16\xcd\x36\xec\xca\x96\xf4\x7e\xf1\xe1\xc3\xf7\x21\xb9\x58\x6c\x6f\x86\x87\x6a\x76\xab\xf9\x78\x62\x61\x77\xe7\xcd\x7f\xb7\x66\x1a\x0d\x4a\x0b\x27\x34\xc1\x91\x52\x57\x30\x90\x09\x81\x03\x21\xc0\x1b\x19\x70\xdf\xf5\x1c\x53\x12\x5e\x4e\xb8\x01\xa3\x32\x9d\x20\x24\x2a\x45\xe0\x06\x04\x4f\x50\x1a\x4c\x21\x93\x29\x6a\xb0\x13\x84\x83\x19\x4d\x26\x08\xbb\x64\xa7\xfa\x0a\x4c\x65\x32\x0d\xb9\xf4\xdf\xdf\x0d\x0e\x8f\xcf\x86\xc7\xc0\xb8\x40\x28\xdf\x69\xa5\x2c\xa4\x5c\x63\x62\x95\xbe\x05\xc5\xc0\x36\x92\x59\x8d\x48\xc2\xcd\xed\x3c\x0f\xc3\xc5\x02\x52\x64\x5c\x22\x6c\xa4\x9c\x0a\x4c\xec\xb6\xb9\x16\xdb\x89\x46\x6a\x71\x03\xf2\xdc\x59\xf4\x46\x19\x17\xae\x9e\xbd\x7d\x98\x51\x93\x50\x01\x3d\x32\x4c\xd4\x0c\xc9\x4f\xe5\x97\xd2\x50\x63\x82\x7c\x5e\x58\x2e\xff\x2f\xdd\x5d\x42\x96\xc9\x04\xa2\x15\xdb\x3c\x87\xcd\x66\x96\x3c\x8f\xc1\x5c\x8b\x21\x9d\x63\x94\xd8\x1b\x48\x94\xb4\x78\x63\xc9\x61\xf1\x1b\x43\xe4\xcd\xc9\x19\x9d\x22\xe4\x79\x1f\x50\x6b\xa5\x63\x58\x84\xc1\x9c\x6a\x88\xc2\x20\xd0\x68\x5c\x08\x72\x81\x26\x13\x36\x0c\x02\xef\x70\xd1\xc8\xb8\x0f\xaf\x9b\x41\x16\x89\x92\x8c\x8f\xf7\xa0\x55\x19\x29\xde\xe7\x61\x10\x87\x81\xbd\xf1\xb9\xdc\xe0\xda\x66\xa9\x76\xff\xc8\xe5\x8d\xab\x38\x0e\x03\xce\xbc\xe5\x7f\xf6\x41\x72\xe1\x2a\x0b\x34\xda\x4c\x4b\xf7\xe8\x83\x84\x41\x1e\x06\x0d\x5c\x5d\xb5\x03\x69\x50\x5b\x0f\x0e\x79\x4f\x93\x2b\x3a\x76\xa5\x91\x4b\x3a\x12\x18\x93\x23\x64\x34\x13\xb6\x8d\x5d\x95\xfa\xa8\x98\xbe\x28\x8e\xc3\x60\xb1\xd8\x02\x4d\xe5\x18\xa1\xf7\x7b\x1f\x7a\xcc\x25\xe8\x91\x13\x8e\x22\x35\x6e\x16\x02\x57\xdf\x9c\x8a\x0c\xbb\xc6\xe2\xbc\x7b\x8c\x0c\xad\xce\x12\xeb\x9d\x20\xcf\xdf\x96\xf6\x8d\x11\xf9\x34\x9c\x39\xdb\x81\xf9\x79\x78\x7e\x56\x84\x0e\x82\x51\xc6\x96\x40\xfd\x61\x94\x24\xa7\x54\x9b\x09\x15\xd1\xa6\x8f\x11\x7b\xa3\xbb\x08\x05\x1d\x20\x05\x41\x50\xc5\xf4\x50\x91\x21\xde\x05\xc8\x3d\x33\x47\x0f\x63\xa9\xb4\x9e\x12\xa3\x8c\xc5\x55\x89\x28\x0c\xd6\xa5\x3d\x2b\x4c\xa3\x60\x1f\x49\xa6\x65\xa0\x36\x9f\x9c\x73\xb5\x34\x58\x45\x2a\xf0\xd8\x72\x06\x52\x59\xff\x9a\x0b\xe1\xe6\x12\xf2\xdc\x31\xb8\x88\xe6\x33\x84\x7e\x98\xcd\x14\xd7\x19\xea\xdb\x3e\x50\x3d\x36\x0e\xc6\xaa\xee\x0f\xee\x75\x54\x13\x6c\x6f\x1f\xec\x0d\x39\xbe\xc1\xc4\x11\xaf\x0f\x0d\xb7\x3e\xbc\xd6\x68\xe2\xb7\x0f\x11\x51\x2b\x21\x46\x34\xb9\x8a\x4a\x6a\xc7\x9e\x96\x3c\x5d\x4e\x9f\x46\x43\xde\x51\x63\x0b\x6a\x0e\xd2\xe8\x51\x6e\x77\x87\xbc\x83\xd7\xe0\x68\x89\x4e\x8f\x0c\x8e\xc8\xc0\x0c\xad\xe6\x72\x0c\x79\x6e\xac\x4e\x94\x9c\x93\x13\xa5\xa7\xd4\x0e\xa4\x8d\x5c\x41\x6f\x76\x62\x87\x59\x31\x97\xdc\xbf\x8c\x97\x20\xde\xa1\x3c\x16\x94\x3f\x4e\xc7\x58\x33\x5e\xa0\xbc\xb3\x7a\xdc\x33\xb6\xb8\x1e\xc3\xff\x61\x67\x85\xe2\x54\xa6\xce\xec\xa3\xe4\xd7\x19\x7a\x07\x14\xec\x02\x99\xeb\x1c\x8b\xed\x4d\x38\xdf\x3d\x87\xaf\xdc\x4e\xc0\xa0\x60\xa0\x91\xa1\x46\x99\x20\xf8\x26\xeb\x78\xc7\x94\x06\xe4\xa9\x87\xd4\x57\xf9\x94\x3a\xaa\x55\xe1\x8a\xb0\x38\x9d\x09\x6a\x3b\xfb\xf4\xb6\x83\x0b\xb5\xe5\xe9\x86\x1b\xf9\x56\x99\xb3\xcd\x21\xd7\x62\x3e\xce\x52\x6a\xb1\x93\xfa\x58\x34\x9a\x06\xff\x63\x52\xc4\x09\x82\xfb\x96\x0b\x92\x43\x25\xb2\xa9\x5c\x59\x34\xc8\xd3\xda\xf3\xb7\x09\x6a\x8c\x5c\xea\xe3\x0f\x9d\x21\xdc\xe4\xaf\xb8\xf3\x34\x8e\x6b\x9e\x37\x5a\xc5\x1a\x5c\x6f\xf7\x94\x0e\x72\xd6\x2d\x66\x05\xaf\x1f\x07\xd7\x83\x68\x21\xb9\xbc\x9d\x61\x47\x6e\xf7\xb6\x8d\x9c\x07\xfe\x40\xa6\x51\x4c\x06\xe6\x2c\x13\xe2\xa9\x45\xbc\x14\xe0\x94\x31\x4c\x2c\xae\xb6\x9b\x0b\xf5\xd5\x1c\x94\x1f\x5a\x05\xad\x9d\x88\x33\x70\x2d\xa3\xca\x17\xc3\xff\x9e\xd1\x0c\x1e\x4d\xf7\xfa\x58\x6b\x8f\xa6\xa6\x5c\xda\x13\xca\x05\xa6\x8b\xa9\x19\xef\x01\x9b\x5a\x32\x9c\x69\x2e\x2d\x8b\x36\x3e\x6f\x14\xf1\x4b\x75\xf8\xbc\x01\xd1\xab\x79\x0c\x54\x68\xa4\xe9\xad\xdb\xe6\x48\x5f\x1d\x58\x05\x14\x52\xce\x7c\x17\xb1\x50\xf8\xd5\x6e\x1b\xc5\x4c\xe7\x2b\x43\xcc\x57\xd4\xce\x75\x55\x24\xa7\xbb\xa7\x00\x2f\xd9\x80\x5c\x4c\xea\x52\xee\xf8\x46\x09\xbd\x91\x7b\x78\xe3\x1f\xb6\xca\x22\x07\x66\xe0\x7c\x7d\x5b\x2f\xec\x2b\x0b\x67\xbe\x74\xad\xa5\xb7\xb3\xaf\xdd\xb3\x75\x7a\x6c\xa1\x16\x2b\xc1\xdc\xe3\xf7\xfe\x97\x86\xd3\xa7\xa2\xb8\x3c\xff\xd2\x87\xa7\x9a\x8f\x9c\x79\x9d\xed\x57\x27\xf5\xc6\xab\xd9\x4a\x8f\xac\xc1\x68\xc9\x8a\x53\x93\x2d\x8d\x0c\x0a\x98\x8d\xdf\xdc\xa3\xd7\x34\x2e\x61\xa4\xec\x04\xbe\xd2\x5b\x43\x6a\x9d\x69\xa4\x41\x97\xa7\x9d\xa6\x09\x63\x10\xbc\xc4\xa2\xef\x26\xea\xf9\x8b\xf2\xf4\xbb\x09\xe5\xda\x3a\xb9\xa6\x4c\x86\x7f\xad\x79\x3c\xdf\x3d\xad\xe6\x71\x56\x01\xf9\xbe\xac\xeb\x45\x26\x76\x46\xce\x75\x14\xaf\x2d\xa6\x8d\xf3\xc7\xf7\xa2\xc8\x9a\x5b\x83\x9a\x1f\x4e\xdf\x67\xfd\xa2\xe9\x3d\x53\xe4\xab\x60\x4d\xba\x7c\x13\x5b\x1e\x27\x4b\x01\xde\x53\x75\xfe\xd1\x33\xe1\x43\x49\xbe\x87\xc6\x7f\xab\xc4\x2b\x89\xa0\x18\xdc\x55\xfa\x57\xf3\xb5\x74\xfe\x0a\x6f\xcd\xd3\x46\x50\x6d\x07\xf2\xd6\xa9\x77\x79\x3c\x59\x4a\x44\xa5\x36\x4b\xda\x37\x8e\x5e\x05\x0a\xd8\x38\x00\x56\x87\xb1\x03\xab\x78\xf4\xf4\x72\x3e\xed\x7c\x79\xf2\xd6\xad\x3a\xe8\x07\x75\x7d\xcd\x23\x7b\x50\x76\x8d\x67\x25\x0f\x3b\x04\xaf\x7b\xcf\xf1\xb7\x56\x80\x75\x77\xfb\x1d\xba\x71\x07\xf6\x97\x81\xe4\x21\x44\x7e\xd8\x61\xe8\x3e\x78\x6a\x2e\xfd\xdb\x36\xff\xa9\x6d\xb3\x9a\xe3\xd6\x7d\xdc\xca\x84\x1f\xaa\xe9\x94\xdb\xe8\xe1\xbb\xb5\xea\x92\xb7\x7c\xd7\xbe\x01\xeb\x3b\xab\xb0\xb8\x82\x2f\x93\x3c\x7c\x1b\xdf\xdc\xe3\x54\x37\x5e\x0f\xf4\xf1\x7b\x9b\x78\xb9\xb1\xe9\x20\xcd\x63\x94\x59\x85\xa4\xae\xfb\xcf\x00\x00\x00\xff\xff\x06\x45\x50\xb8\x09\x19\x00\x00") +var _templateDialectSqlCreateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x58\xdf\x53\xdb\xb8\x16\x7e\xb6\xff\x8a\x73\x19\xda\xb1\x99\x20\x28\x6f\x97\x5e\xee\x0c\xcb\x8f\x99\xec\x16\x68\x09\xdd\x7d\x68\x3b\x3b\x8a\x7d\x94\x68\x51\xa4\x20\xc9\x29\x4c\xc6\xff\xfb\x8e\x64\x3b\x76\x8c\x81\x90\x76\xca\xee\xce\x3e\x25\xb6\xcf\x2f\x7d\xfa\x74\x3e\x49\xf3\xf9\xce\x56\x78\xa4\xa6\x77\x9a\x8f\xc6\x16\xf6\x76\xdf\xfc\x77\x7b\xaa\xd1\xa0\xb4\x70\x4a\x13\x1c\x2a\x75\x0d\x7d\x99\x10\x38\x14\x02\xbc\x91\x01\xf7\x5d\xcf\x30\x25\xe1\xd5\x98\x1b\x30\x2a\xd3\x09\x42\xa2\x52\x04\x6e\x40\xf0\x04\xa5\xc1\x14\x32\x99\xa2\x06\x3b\x46\x38\x9c\xd2\x64\x8c\xb0\x47\x76\xab\xaf\xc0\x54\x26\xd3\x90\x4b\xff\xfd\x5d\xff\xe8\xe4\x7c\x70\x02\x8c\x0b\x84\xf2\x9d\x56\xca\x42\xca\x35\x26\x56\xe9\x3b\x50\x0c\x6c\x23\x99\xd5\x88\x24\xdc\xda\xc9\xf3\x30\x9c\xcf\x21\x45\xc6\x25\xc2\x46\xca\xa9\xc0\xc4\xee\x98\x1b\xb1\x93\x68\xa4\x16\x37\x20\xcf\x9d\xc5\xe6\x30\xe3\xc2\xd5\xb3\x7f\x00\x53\x6a\x12\x2a\x60\x93\x0c\x12\x35\x45\xf2\x53\xf9\xa5\x34\xd4\x98\x20\x9f\x15\x96\x8b\xff\x0b\x77\x97\x90\x65\x32\x81\x68\xc9\x36\xcf\x61\xab\x99\x25\xcf\x63\x30\x37\x62\x40\x67\x18\x25\xf6\x16\x12\x25\x2d\xde\x5a\x72\x54\xfc\xc6\x10\x79\x73\x72\x4e\x27\x08\x79\xde\x03\xd4\x5a\xe9\x18\xe6\x61\x30\xa3\x1a\xa2\x30\x08\x34\x1a\x17\x82\x5c\xa2\xc9\x84\x0d\x83\xc0\x3b\x5c\x36\x32\x1e\xc0\xeb\x66\x90\x79\xa2\x24\xe3\xa3\x7d\x68\x55\x46\x8a\xf7\x79\x18\xc4\x61\x60\x6f\x7d\x2e\x37\xb8\xb6\x59\xaa\xdd\x3f\x72\x75\xeb\x2a\x8e\xc3\x80\x33\x6f\xf9\x9f\x03\x90\x5c\xb8\xca\x02\x8d\x36\xd3\xd2\x3d\xfa\x20\x61\x90\x87\x41\x03\x57\x57\x6d\x5f\x1a\xd4\xd6\x83\x43\xde\xd3\xe4\x9a\x8e\x5c\x69\xe4\x8a\x0e\x05\xc6\xe4\x18\x19\xcd\x84\x6d\x63\x57\xa5\x3e\x2e\xa6\x2f\x8a\xe3\x30\x98\xcf\xb7\x41\x53\x39\x42\xd8\xfc\xbd\x07\x9b\xcc\x25\xd8\x24\xa7\x1c\x45\x6a\xdc\x2c\x04\xae\xbe\x19\x15\x19\x76\x8d\xc5\x79\x6f\x32\x32\xb0\x3a\x4b\xac\x77\x82\x3c\x7f\x5b\xda\x37\x46\xe4\xd3\x70\xe6\x6c\xfb\xe6\xe7\xc1\xc5\x79\x11\x3a\x08\x86\x19\x5b\x00\xf5\x87\x51\x92\x9c\x51\x6d\xc6\x54\x44\x5b\x3e\x46\xec\x8d\xee\x23\x14\x74\x80\x14\x04\x41\x15\xd3\x43\x45\x06\x78\x1f\x20\xf7\xcc\x1c\x3d\x8c\xa5\xd2\x7a\x4a\x0c\x33\x16\x57\x25\xa2\x30\x58\x97\xf6\xac\x30\x8d\x82\x7d\x24\x99\x96\x81\xda\x7c\x72\xce\xd5\xd2\x60\x15\xa9\xc0\x63\xcb\x19\x48\x65\xfd\x6b\x2e\x84\x9b\x4b\xc8\x73\xc7\xe0\x22\x9a\xcf\x10\xfa\x61\x36\x53\xdc\x64\xa8\xef\x7a\x40\xf5\xc8\x38\x18\xab\xba\x3f\xb8\xd7\x51\x4d\xb0\xfd\x03\xb0\xb7\xe4\xe4\x16\x13\x47\xbc\x1e\x34\xdc\x7a\xf0\x5a\xa3\x89\xdf\x3e\x46\x44\xad\x84\x18\xd2\xe4\x3a\x2a\xa9\x1d\x7b\x5a\xf2\x74\x31\x7d\x1a\x0d\x79\x47\x8d\x2d\xa8\xd9\x4f\xa3\x27\xb9\xdd\x1d\xf2\x1e\x5e\xfd\xe3\x05\x3a\x9b\xa4\x7f\x4c\xfa\x66\x60\x35\x97\x23\xc8\x73\x63\x75\xa2\xe4\x8c\x9c\x2a\x3d\xa1\xb6\x2f\x6d\xe4\x0a\x7a\xb3\x1b\x3b\xcc\x8a\xb9\xf4\xe1\xfa\xc7\xe4\xea\x6e\xea\x1e\x23\x9e\xc6\x0b\x40\xef\xd1\x1f\x0b\xfa\x9f\xa4\x23\xac\xd9\x2f\x50\xde\x5b\x49\xee\x19\x5b\xbc\x8f\xe1\xff\xb0\xbb\x44\x77\x2a\x53\x67\xf6\x51\xf2\x9b\x0c\xbd\x03\x0a\x76\x89\xcc\x97\xb5\xb3\x05\x17\x7b\x17\xf0\x95\xdb\x31\x18\x14\x0c\x34\x32\xd4\x28\x13\x04\xdf\x70\x1d\x07\x99\xd2\x80\x3c\xf5\xf0\xfa\x2a\x57\xa9\xa3\x5a\x21\xae\x08\x8b\x93\xa9\xa0\xb6\xb3\x67\xef\x38\xe8\x50\x5b\x9e\x6e\xb8\x91\x6f\x97\x39\xdb\x7c\x72\xed\xe6\xe3\x34\xa5\x16\x3b\x97\x01\x16\x4d\xa7\xb1\x16\x62\x52\xc4\x09\x82\x87\x96\x0e\x92\x23\x25\xb2\x89\x5c\x5a\x40\xc8\xd3\xda\xf3\xb7\x31\x6a\x8c\x5c\xea\x93\x0f\x9d\x21\xdc\x94\x2e\xb9\xf3\x34\x8e\x6b\xce\x37\xda\xc6\x1a\xbc\x6f\xf7\x97\x0e\xa2\xd6\xed\x66\x09\xaf\x1f\x07\xd7\xa3\x68\xa1\xa7\x7b\x47\x6e\xf7\xb6\x8d\x9c\x07\xfe\x50\xa6\x51\x4c\xfa\xe6\x3c\x13\x62\xd5\x22\x5e\x0a\x70\xca\x18\x26\x16\x97\x5b\xcf\xa5\xfa\x6a\x0e\xcb\x0f\xad\x82\xd6\x4e\xc4\x19\x70\x69\xa3\x2a\x5f\x0c\xff\x7b\x46\x33\x78\x32\xdd\xeb\x13\xad\x3d\x9a\x9a\x72\x69\x4f\x29\x17\x98\xce\x27\x66\xb4\x0f\x6c\x62\xc9\x60\xaa\xb9\xb4\x2c\xda\xf8\xbc\x51\xc4\x2f\x95\xe2\xf3\x06\x44\xaf\x66\x31\x50\xa1\x91\xa6\x77\x6e\xcb\x23\x7d\x75\x60\x15\x50\x48\x39\xf3\x5d\xc4\x42\xe1\x57\xbb\x6d\x14\x33\x9d\x2f\x0d\x31\x5f\x52\x3e\xd7\x61\x91\x9c\xed\x9d\x01\xbc\x64\x03\x72\x31\xa9\x4b\xb9\x5b\xf6\xef\xa1\x7b\x78\xe3\x1f\xb6\xcb\x22\xfb\xa6\xef\x7c\x17\x2d\x9e\x42\x65\xe1\xcc\x17\xae\xb5\x0c\x77\xf6\xb5\x07\xb6\x51\x4f\x2d\xd4\x62\x25\x98\x07\xfc\xde\xff\xd2\x70\xfa\x54\x14\x97\xe7\x5f\x7a\xb0\xaa\xf9\xd0\x99\xd7\xd9\x7e\x75\xb2\x6f\xbc\xb2\x2d\xf5\xc8\x1a\x8c\x96\xac\x38\x35\xd9\xd6\xc8\xa0\x80\xd9\xf8\x8d\x3e\x7a\x4d\xe3\x12\x86\xca\x8e\xe1\x2b\xbd\x33\xa4\xd6\x99\x46\x1a\x74\x79\xda\x69\x9a\x30\x06\xc1\x4b\x2c\xfa\x6e\xa2\x5e\xbc\x28\x4f\xbf\x9b\x50\xae\xad\x93\x6b\xca\x64\xf8\xd7\x9a\xc7\x8b\xbd\xb3\x6a\x1e\xa7\x15\x90\xef\xcb\xba\x5e\x64\x62\xa7\xe4\x42\x47\xf1\xda\x62\xda\x38\x8b\x7c\x2f\x8a\xac\xb9\x35\xa8\xf9\xe1\xf4\x7d\xda\x2b\x9a\xde\x33\x45\xbe\x0a\xd6\xa4\xcb\x37\xb1\xe5\x69\xb2\x14\xe0\xad\xaa\xf3\x4f\x9e\x0f\x1f\x4b\xf2\x3d\x34\xfe\x5b\x25\x5e\x49\x04\xc5\xe0\xbe\xd2\xbf\x9a\xad\xa5\xf3\xd7\x78\x67\x56\x1b\x41\xb5\x1d\xc8\x5b\x27\xe0\xc5\xf1\x64\x21\x11\x95\xda\x2c\x68\xdf\x38\x86\x15\x28\x60\xe3\x30\x58\x1d\xcc\x0e\xad\xe2\xd1\xea\xe5\x7c\xda\xfd\xb2\xf2\xd6\xad\x3a\xf4\x07\x75\x7d\xcd\xe3\x7b\x50\x76\x8d\x67\x25\x0f\x3b\x04\xaf\x7b\xcf\xf1\xb7\x56\x80\x75\x77\xfb\x1d\xba\x71\x0f\xf6\x97\x81\xe4\x31\x44\x7e\xd8\x61\xe8\x21\x78\x6a\x2e\xfd\xdb\x36\xff\xa9\x6d\xb3\x9a\xe3\xd6\xdd\xdc\xd2\x84\x1f\xa9\xc9\x84\xdb\xe8\xf1\x7b\xb6\xea\xc2\xb7\x7c\xd7\xbe\x0d\xeb\x39\xab\xb0\xb8\x8e\x2f\x93\x3c\x7e\x33\xdf\xdc\xe3\x54\x37\x5e\x8f\xf4\xf1\x07\x9b\x78\xb9\xb1\xe9\x20\xcd\x53\x94\x59\x86\xa4\xae\xfb\xcf\x00\x00\x00\xff\xff\x6f\x02\x81\xbd\x15\x19\x00\x00") func templateDialectSqlCreateTmplBytes() ([]byte, error) { return bindataRead( @@ -552,7 +552,7 @@ func templateDialectSqlCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6409, mode: os.FileMode(420), modTime: time.Unix(1568799191, 0)} + info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6421, mode: os.FileMode(420), modTime: time.Unix(1569233725, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -717,7 +717,7 @@ func templateDialectSqlSelectTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlUpdateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x5b\x5d\x6f\xdb\x38\xd6\xbe\x96\x7f\xc5\x19\x23\xed\x48\x79\x5d\x25\xed\xdd\x9b\xae\x0b\x64\x93\x14\xf0\xee\x36\xee\xd4\x9d\xdd\x8b\x4e\x51\x30\xd2\x51\xcc\x8d\x4c\x39\x24\xed\x24\x1b\xe8\xbf\x2f\x0e\xa9\x0f\x4a\x96\x5d\x3b\x09\xda\x0e\xba\x03\x4c\x6b\x89\x5f\xe7\x8b\xcf\x79\x0e\xc5\xde\xdf\x1f\xec\xf7\x4e\xb2\xf9\x9d\xe4\x97\x53\x0d\xaf\x0e\x5f\xfe\xff\x8b\xb9\x44\x85\x42\xc3\x5b\x16\xe1\x45\x96\x5d\xc1\x48\x44\x21\x1c\xa7\x29\x98\x4e\x0a\xa8\x5d\x2e\x31\x0e\x7b\x1f\xa7\x5c\x81\xca\x16\x32\x42\x88\xb2\x18\x81\x2b\x48\x79\x84\x42\x61\x0c\x0b\x11\xa3\x04\x3d\x45\x38\x9e\xb3\x68\x8a\xf0\x2a\x3c\x2c\x5b\x21\xc9\x16\x22\xee\x71\x61\xda\xff\x31\x3a\x39\x3b\x9f\x9c\x41\xc2\x53\x84\xe2\x9d\xcc\x32\x0d\x31\x97\x18\xe9\x4c\xde\x41\x96\x80\x76\x16\xd3\x12\x31\xec\xed\x1f\xe4\x79\xaf\x77\x7f\x0f\x31\x26\x5c\x20\xf4\x63\xce\x52\x8c\xf4\x81\xba\x4e\x0f\x16\xf3\x98\x69\xec\x43\x9e\x53\x8f\xbd\xf9\xd5\x25\x1c\x0d\x61\x2f\x9c\x44\xd9\x1c\xc3\xf7\x2c\xba\x62\x97\x58\xb6\x5e\x2c\x78\x4a\xd2\x1e\x0d\x61\xce\x54\xc4\xd2\xaa\xe3\x5f\x8b\x96\xa2\xa3\xc4\x08\xf9\xd2\xf6\xac\x7e\x57\xc3\x8b\x4e\x99\x40\x6a\x9f\x32\x35\x59\x24\x09\xbf\xad\x3b\xf4\xc7\xa2\x14\xe9\x05\xec\xfd\x07\x65\x46\x1d\x0f\x21\xcf\xef\xef\x81\x27\x76\xa8\x79\xb0\x8d\x43\xe8\x0b\x9e\xf6\xed\x2b\x14\x71\x35\x54\xa2\xa6\x91\x7d\xd1\xef\x1a\x4b\xad\xa4\xeb\x87\x52\x42\x77\x7c\x2f\x59\x88\x08\xfc\x86\x36\x79\x0e\xfb\xae\x1d\xf2\x3c\x00\x75\x9d\x4e\xd8\x12\xfd\x48\xdf\x42\x94\x09\x8d\xb7\x3a\x3c\xb1\x7f\x07\xe5\x70\x4d\x23\x1b\xcb\x9b\x69\xc2\x73\x36\x2b\x64\xc1\x54\xd1\x2f\x2e\x74\x25\xc1\x00\x50\x4a\xfa\x3f\x93\x01\xdc\xf7\x3c\x85\xa9\xf1\x32\x29\xa4\xae\xd3\x70\x62\x9e\xcd\x0a\x8e\x9f\xc2\xc6\x32\x27\x59\xba\x98\x09\x15\x86\x61\xbd\x86\x19\x30\x3a\x25\x21\x95\x66\x42\xbb\x5a\x07\xe1\x5b\x99\xcd\x7c\x9a\xfe\x23\xbb\x48\x71\x65\x76\xf3\x36\x08\x7a\x1e\x99\xb7\x5e\xa7\xe7\x79\xed\x9e\xa3\xd3\xb6\xed\x42\x1e\x07\x7e\xa9\x45\x31\x45\x21\x53\xcf\xf3\x92\x4c\xc2\x97\x01\xcc\x4d\xc8\x30\x71\x89\xd0\x1e\x3e\x97\x18\xf3\x88\x69\x54\x64\x0e\xcf\x9b\xbb\x93\x79\x79\x31\xa1\xf5\x9e\x27\xb3\x1b\x45\x53\x3d\x27\x5d\x3e\x64\x37\xea\x3e\xef\x79\xd7\x0b\x94\x77\x03\x60\xf2\xd2\xb4\x95\xc3\xc3\xdf\xe8\xbd\x1f\xf4\x3c\x9e\x18\xa3\x0f\x57\xd6\x8e\x25\xfd\x2a\x3a\x46\xfa\x76\x00\xce\x5c\x03\xa0\xd5\x82\xd7\x66\xec\x2f\x43\x10\x3c\x35\x12\x4a\xd4\x0b\x29\xa0\x0a\xd3\xc2\xa7\x3d\x92\x35\xc6\x04\xa5\x19\x17\x9e\xa4\x99\x42\x5a\x7d\xc9\x24\xf0\x58\xc1\xa7\xcf\x5c\xe8\x9e\xb1\x88\xe9\x70\x8e\xb7\xda\x37\x31\x50\x74\x01\xd3\xbe\xea\x03\xeb\x04\x27\x9c\x61\x08\xcf\x1b\x91\x16\x65\x22\xe1\x97\x47\x2b\xfa\xd9\xf7\x66\x8e\xc2\x06\x47\xd6\x08\xee\x6c\x26\x38\xc8\x96\x7e\xb7\xbe\xdd\x1a\x27\x33\x1d\x9e\x51\x14\x27\x7e\xbf\x84\x98\x3c\x3f\x82\x84\xf1\x14\x63\x50\x11\x13\x82\x8b\x4b\x52\x95\xf4\xca\xc0\x15\xf8\x08\x9e\x2d\xfb\xc6\x6a\xe4\x63\xcf\x0a\x18\x43\x87\x6c\xa5\x31\x28\xb4\x47\x6a\xa2\x25\xcd\x99\xe7\x3c\xf6\x83\x3a\xf6\x47\xa7\xf5\x06\xf7\x5a\x01\xe8\x28\x6e\xac\x3e\x89\x98\xf0\x9f\xf3\xf8\x89\xf4\x94\xc8\x62\x12\x89\xc7\x1d\x3a\xb9\x91\xeb\x51\x08\x0c\x81\xcd\xe7\x28\x62\x9f\xc7\x6a\x00\x3c\x0e\x7a\x65\x80\x37\x1c\xae\x6e\xb8\x8e\xa6\x20\x48\xe8\x14\x05\xf5\x0e\x5e\x1b\x19\x23\xa6\x10\x04\x0c\x87\x70\x78\xd4\xdb\x51\x62\xd7\x01\x20\x32\x6d\xd3\x10\xdc\x70\x3d\xad\xc5\xef\xd8\xdc\xf5\xb2\x6f\xe0\xe5\xce\xab\xce\x32\x89\xa0\xa7\x4c\x00\xa9\xd7\x90\xc1\xac\x4c\xe9\x4e\xd1\x8b\xaf\x88\x90\xb7\x91\x85\x27\x95\x6d\x8c\x3d\xac\x0f\xbb\x44\x13\x3c\x5d\x45\x12\x4a\xfe\x64\x75\x3d\x45\x89\xbf\x52\x6e\x9d\xa1\x9e\x92\x2b\x75\x06\x36\x7d\x0e\x40\x69\x26\x35\x30\xd0\x92\x09\xc5\x22\xcd\x33\x11\x82\x49\xbc\x1e\x81\x85\xb3\xa1\x3a\x50\xe5\xe3\x2d\x41\x4a\x0d\x3f\x5b\x42\x48\x15\xf1\x6f\x39\xa6\xb1\xb2\xca\x12\x40\xf8\x56\x3f\x65\xd2\xc4\x07\x54\x8b\x94\xd0\xc2\x2b\xb3\x96\x4d\x1f\xbf\x1b\xc9\xd7\x00\x7c\xf8\x2f\x52\xd6\xe4\x81\x91\x18\x09\xad\xba\xd2\x4c\x3b\x8b\x50\x9c\x52\xaa\xa1\xf4\xe0\x05\x45\x54\x5b\x28\xdf\xfb\x32\x80\xbd\xc4\x32\x0b\x57\xda\x52\x87\x4c\x82\x4f\x81\xb6\x97\x84\xa3\xd9\x6c\xa1\x8d\x10\xf4\x64\xa5\x3c\xc5\x84\x2d\x52\x5d\x8c\x21\x33\x2d\x59\xba\xc0\x2e\x93\xd2\x73\x12\x4e\xb4\x5c\x44\xda\xac\x04\x79\xfe\xba\xe8\xde\xd8\xc2\x95\xf9\x92\x70\xa4\xfe\x36\x19\x9f\x97\xb3\x93\xa1\x92\xca\x65\xff\x56\x99\x08\xdf\x31\xa9\xa6\x2c\xf5\xf7\xcd\x3c\x41\xd1\x6d\xd5\x5b\xde\x3a\x6c\x30\x2e\x33\xff\xd5\x6b\x18\x67\x84\x13\xec\x4c\xe1\x7b\x49\xd3\xb2\x17\x8b\x24\xa8\xc5\x76\x40\x6b\xf7\xa9\x1a\x4a\x34\x80\xc7\xeb\x4a\x29\x1d\x59\x85\x66\x2d\xf9\x5f\x52\x6d\xd2\x61\xc1\x70\x0a\x3f\x9e\xf3\x34\x25\x37\x16\x64\xc7\x2e\x62\x96\xee\x5c\xd9\xfe\x59\xfb\xe4\xe3\xdd\x1c\xc3\xf3\xc5\x0c\x25\x8f\x2a\x49\x36\x39\x9e\xc5\xf1\xf6\xbe\xaf\x6c\x76\x1c\xc7\x3b\xdb\xac\xdb\x48\x8e\xec\x8e\xea\x65\x23\x89\xbe\x9d\x19\xdb\xe1\xe4\x79\xfb\xdb\x0d\xfc\xbf\x61\x21\x66\x35\x32\xb7\x81\xe2\x4c\xb5\xad\x27\x5b\xf3\xb8\x2a\x36\x63\x6f\xdb\x29\x57\x84\x6b\x07\xde\xca\x8b\x3a\x20\xea\xb7\xab\x4f\xd6\xe0\xe3\x39\x01\x2e\x4b\x1d\x80\x58\x21\x38\x29\x32\xd9\x15\x20\x6d\x38\x68\x45\xfe\x06\x9f\x6e\x6b\x4c\x9b\x55\xd6\xd8\x8f\xf0\xda\x46\xa8\x15\x8e\xe2\xfe\x01\x6b\xb8\xb6\xed\xda\xd3\xee\xb3\x83\x17\xe7\x8b\x34\xfd\x7a\xfc\x07\xf5\x0e\x6d\xcc\xd5\x64\x2d\x09\xfc\x52\xce\x7c\x36\x9b\xeb\xbb\x82\xb1\xb6\x49\x77\xd9\xa7\xe2\xdc\x2e\xf1\xd2\xb7\xe1\xd9\x2d\x46\x1d\x0c\xfb\xb9\xc4\xad\x19\xa7\xcc\xd2\xf4\x82\x45\x57\x7e\x91\x7a\x2b\x9a\xe5\x52\x03\x93\x39\xcf\xe2\x4b\x54\xa6\x00\x3a\xd8\x07\xaa\xe6\x89\x69\x64\x0b\x0d\x89\x49\x52\x84\xbb\xf6\x1d\xa0\xe9\x69\x33\xba\x71\x5a\x3b\xbf\x36\x29\x43\x23\xf1\xa1\x4d\x7c\xe5\x62\x0e\x73\xc7\xf0\xdd\xab\x77\x35\xfd\x24\x9a\xd2\x0e\x5c\x89\xb3\x6c\x89\xb1\xe3\x77\x2c\xfd\x1e\xc0\x9b\x92\xcd\x98\x19\xf7\x98\x53\x26\xef\x5d\xd0\xc3\xcb\xba\xee\xc5\x70\xa4\x46\x62\x89\xb2\xaa\x02\x19\x54\x1d\xf6\x2e\xa0\x1a\xe9\xc4\x0a\x12\x17\x3d\x1a\xc2\x8c\x5d\xa1\x6f\xca\x92\xc1\xce\x42\xda\xe8\xa1\x62\x06\x79\xbc\xbe\xba\xdb\x30\x85\xbb\x45\x35\xce\xe6\x29\xd3\x9d\xa7\x18\x07\x51\x46\xfa\x69\x1e\xf7\xc9\xe8\x2f\xca\x80\xc7\x06\xa3\x46\x43\xa9\xd1\x92\xc5\x12\x67\xda\x95\xe1\x75\x1a\x9e\x62\x8a\x1d\x04\x89\x9e\xd1\xd2\x24\x77\x8b\x84\x76\xa9\xad\x78\x13\x86\xef\xff\xee\x8c\xfd\x64\x7d\x91\xe7\x9f\x6b\x06\xf5\xd8\xe9\x2e\xec\x74\xd8\x9a\xcf\xd9\x74\x8f\xda\x75\xdb\x6f\xbb\x56\x62\xc7\x70\x82\x69\xf2\x01\x93\x72\xd3\x51\xfc\x9b\x0d\xa6\x30\x4d\x40\x52\x55\x8c\x22\x42\xb3\xd3\x4c\x87\x8f\xe3\xd3\xf1\x11\x2c\x14\xc2\xf8\x43\x79\xea\x65\xaa\x0c\x76\x91\x2d\xb1\x24\xd9\x6d\x1f\x3e\xc2\x85\x8f\x36\x7a\xcb\xe6\x8f\x8e\x89\xb6\x13\x1b\x5e\x7c\xa4\x1f\x77\xf1\x64\x77\x4e\x6e\x14\xd2\xd6\xc5\xe3\x27\xc2\xb4\x9f\x19\x7d\xd6\x94\x67\x9b\x43\x77\x53\x46\xc7\xd0\x1e\x06\x3e\x1c\xb4\x56\xc6\x6f\x07\x57\x68\xb9\xfc\xaa\x12\xf4\xb6\x5d\x41\xfe\x28\x80\xd5\x3a\x1e\x32\x48\x34\x7e\x35\xa6\x42\xf5\xdd\xab\x71\x05\x3a\xeb\x88\xe6\xc6\x48\xfa\x11\xbd\xbd\x93\x93\x7e\x10\x1f\xad\x4f\x2a\xe4\xa9\x75\x49\x65\x5d\xae\x78\x90\x0b\x1e\xea\x83\xa7\xdb\x72\xcd\x64\xf0\xb8\x5c\xb0\x43\x2a\xd8\x98\x09\x9c\x92\xa0\x0b\xae\xad\x6a\xcd\x2a\xcc\x81\xfd\xc2\xab\x4c\xc4\xd4\xed\x77\xc1\xaf\x17\xf8\x10\x1f\xf3\xa4\x7d\x2e\x6a\xce\x25\xb7\x0e\xb6\x75\xe7\x94\x11\x13\xbf\x6a\x48\xb9\xb8\x32\x32\x50\x61\x00\x7f\xf4\xad\x52\xc5\x46\xff\xa3\x0f\x3a\x83\x67\x31\x98\x7c\x10\xa1\x02\xff\x0d\xbc\x0c\xfa\x03\x10\x81\x1b\xc0\x5f\x4d\x4b\x5d\xa6\x7a\x6c\x3e\x7a\x2a\xf8\x31\xc1\xbf\x7d\xdc\x52\xca\xab\x46\xd6\xe1\x7f\xf6\xdb\xd6\x47\x8b\x9f\x0e\x3f\x07\x41\xf8\x3d\xe3\xfd\xc9\x60\x63\x37\xd3\x15\xba\xaf\xb7\xde\xae\x29\x36\x08\x8f\x45\xec\x07\xe1\x48\xed\x04\x5e\xdf\xd9\xf8\x2c\x49\x30\xd2\x18\x57\x67\xb3\x12\x95\xf9\xb4\x77\x5c\x34\xb4\x04\x7b\xf4\x82\x3c\x01\x2e\xb4\x5f\xae\x1b\xc0\x5f\x76\xc0\xb3\xad\x97\x7d\x7e\x26\xa5\xb1\xb2\x64\x5c\xe8\xb7\xe6\x6b\xd1\xfd\x4c\x5d\x1e\x19\x04\x9a\xcc\x25\x17\x3a\xf1\xfb\xab\x10\xe3\x3f\x5b\x06\xc0\x52\x89\x2c\xbe\x83\x28\x13\xc2\x48\x49\xc8\xc3\x20\xe6\x89\x01\x44\x5d\x40\x53\x3d\xac\x6f\x23\x20\x6f\xa8\x5a\x9f\xed\xd4\x2c\x9e\x2a\xb3\xf2\x1c\xc0\x1c\x2f\xb9\x5c\xbc\x60\xe3\x87\x83\x0a\x5e\x6b\xa2\xfd\x85\x22\xb6\xc6\x34\xa2\xbf\x85\x31\x1e\x85\x77\x0f\x06\xbc\x52\xfa\x8a\x83\xdb\xe7\x81\xfd\xce\x7a\xcf\x63\x63\x91\x7c\x00\x5d\x7c\xc2\xf6\x41\xea\xc4\x63\xe7\x43\xb9\xc9\x41\x94\x7a\x5e\x48\x4c\x20\x92\x68\xbe\x4b\x53\x71\x6a\x4f\x8a\xb8\x80\x8b\x4c\x4f\xe1\x86\xdd\x29\xb7\x48\x6d\x9f\x76\x3f\xfd\x99\x8d\x73\x49\xc3\xf2\x0b\x85\x72\x1d\xd8\xac\x03\xa8\xe2\xde\xc0\xae\x95\xea\x4e\x85\x72\x23\x60\x96\x75\x4c\x14\xde\xba\x6f\x1e\x56\xfe\xd3\xbc\xf5\x97\x9f\x0e\x3f\x0f\x60\xf9\xe9\xe5\xe7\x0d\xf5\x53\xc7\x11\xe3\x37\x25\xa6\x2b\x1b\x69\x5c\xfa\xe6\xcf\x9d\xf0\x1f\x9c\xef\x1f\xf7\x35\xf1\x47\x60\xba\x5d\x7e\xad\x8f\x39\xbe\x02\x7b\xf3\xd2\xec\xef\x4b\xe9\xbf\x13\x10\xce\xc3\xb1\xf4\x83\x07\xb3\x86\xb5\x54\xe8\xdb\x45\x55\x67\x50\x11\x99\x99\x0f\x2c\xda\xed\xc8\x68\x7e\x88\xe0\xfa\xc9\x99\x4d\x26\x10\xb2\xa4\xa3\x86\x7a\xb6\x7c\x10\xbd\xb9\xc2\x3b\xb5\x9d\x2a\x1b\x59\x90\x53\x67\x56\xe9\x7b\xf3\x3e\xaf\x2e\x64\x94\x3b\xc8\xb9\x87\x54\xd8\xcc\x10\x09\x55\x78\x59\x69\x49\x3b\x35\x3c\xd6\x19\xf7\xb7\x97\x9a\x6a\x81\xfa\xec\x57\x3d\xcd\xa1\x6e\xc7\xb7\xc9\x02\xa0\x76\x12\xcc\x99\xab\xe3\x56\x41\x93\xce\x14\xcb\xfc\x59\xeb\xd1\x07\x17\x51\xe5\xa2\x0d\xc8\x59\x35\xff\x77\xb2\xcb\x46\xb3\x7c\xb3\x42\x73\xbd\x8d\x9c\xb0\xfa\x1f\x4c\xff\xe4\x30\x5d\xc6\x42\xeb\xc6\x5e\x75\x8b\x57\xdf\x86\x27\xd9\x6c\xc6\xb5\xbf\xdb\xe5\xdc\xba\xad\x79\x61\xbc\x7d\x53\xdc\xee\xd7\xb2\x02\x76\x6e\x6e\x0b\x9e\xf6\xec\x9d\xfb\xf2\x36\xf9\xc6\xeb\xf7\x2e\x61\xcb\xdd\x9b\x7d\xdd\x89\x64\x7d\x12\x29\x58\x5a\x57\x5a\xb0\x16\x69\x38\x5e\x95\x01\x57\xe9\x7b\xb0\x0f\xc5\x6f\xae\xcc\x45\xae\x2b\x71\x93\x09\x60\xda\xfe\xb3\x82\x79\xc6\x85\xae\xaa\xd9\xa6\xd5\x6b\x5d\xff\x1b\x00\x00\xff\xff\x4c\x3e\x7c\x48\x2e\x31\x00\x00") +var _templateDialectSqlUpdateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x5b\x5d\x6f\xdb\x38\xd6\xbe\x96\x7f\xc5\x19\x23\xed\x48\x79\x5d\x25\xed\xdd\x9b\xd9\x0c\x90\x4d\x52\xc0\xbb\xdb\xb8\x13\x77\x76\x2f\x3a\x45\xc1\x48\x47\x31\x37\x32\xe5\x90\xb4\x93\x6c\xa0\xff\xbe\x38\xa4\x3e\x28\x59\x76\xed\x38\x68\x3b\xe8\x0e\x30\xad\x25\x7e\x9d\x2f\x3e\xe7\x39\x14\xfb\xf8\x78\xb0\xdf\x3b\xcd\x66\x0f\x92\x5f\x4f\x34\xbc\x39\x7c\xfd\xff\xaf\x66\x12\x15\x0a\x0d\x6f\x59\x84\x57\x59\x76\x03\x43\x11\x85\x70\x92\xa6\x60\x3a\x29\xa0\x76\xb9\xc0\x38\xec\x7d\x98\x70\x05\x2a\x9b\xcb\x08\x21\xca\x62\x04\xae\x20\xe5\x11\x0a\x85\x31\xcc\x45\x8c\x12\xf4\x04\xe1\x64\xc6\xa2\x09\xc2\x9b\xf0\xb0\x6c\x85\x24\x9b\x8b\xb8\xc7\x85\x69\xff\xc7\xf0\xf4\xfc\x62\x7c\x0e\x09\x4f\x11\x8a\x77\x32\xcb\x34\xc4\x5c\x62\xa4\x33\xf9\x00\x59\x02\xda\x59\x4c\x4b\xc4\xb0\xb7\x7f\x90\xe7\xbd\xde\xe3\x23\xc4\x98\x70\x81\xd0\x8f\x39\x4b\x31\xd2\x07\xea\x36\x3d\x98\xcf\x62\xa6\xb1\x0f\x79\x4e\x3d\xf6\x66\x37\xd7\x70\x74\x0c\x7b\xe1\x38\xca\x66\x18\xbe\x67\xd1\x0d\xbb\xc6\xb2\xf5\x6a\xce\x53\x92\xf6\xe8\x18\x66\x4c\x45\x2c\xad\x3a\xfe\xb5\x68\x29\x3a\x4a\x8c\x90\x2f\x6c\xcf\xea\x77\x35\xbc\xe8\x94\x09\xa4\xf6\x09\x53\xe3\x79\x92\xf0\xfb\xba\x43\x7f\x24\x4a\x91\x5e\xc1\xde\x7f\x50\x66\xd4\xf1\x10\xf2\xfc\xf1\x11\x78\x62\x87\x9a\x07\xdb\x78\x0c\x7d\xc1\xd3\xbe\x7d\x85\x22\xae\x86\x4a\xd4\x34\xb2\x2f\xfa\x5d\x63\xa9\x95\x74\xbd\x2c\x25\x74\xc7\xf7\x92\xb9\x88\xc0\x6f\x68\x93\xe7\xb0\xef\xda\x21\xcf\x03\x50\xb7\xe9\x98\x2d\xd0\x8f\xf4\x3d\x44\x99\xd0\x78\xaf\xc3\x53\xfb\x77\x50\x0e\xd7\x34\xb2\xb1\xbc\x99\x26\xbc\x60\xd3\x42\x16\x4c\x15\xfd\xe2\x42\x57\x12\x0c\x00\xa5\xa4\xff\x33\x19\xc0\x63\xcf\x53\x98\x1a\x2f\x93\x42\xea\x36\x0d\xc7\xe6\xd9\xac\xe0\xf8\x29\x6c\x2c\x73\x9a\xa5\xf3\xa9\x50\x61\x18\xd6\x6b\x98\x01\xc3\x33\x12\x52\x69\x26\xb4\xab\x75\x10\xbe\x95\xd9\xd4\xa7\xe9\x3f\xb0\xab\x14\x97\x66\x37\x6f\x83\xa0\xe7\x91\x79\xeb\x75\x7a\x9e\xd7\xee\x39\x3c\x6b\xdb\x2e\xe4\x71\xe0\x97\x5a\x14\x53\x14\x32\xf5\x3c\x2f\xc9\x24\x7c\x1e\xc0\xcc\x84\x0c\x13\xd7\x08\xed\xe1\x33\x89\x31\x8f\x98\x46\x45\xe6\xf0\xbc\x99\x3b\x99\x97\x17\x13\x5a\xef\x79\x32\xbb\x53\x34\xd5\x4b\xd2\xe5\x32\xbb\x53\x8f\x79\xcf\xbb\x9d\xa3\x7c\x18\x00\x93\xd7\xa6\xad\x1c\x1e\xfe\x46\xef\xfd\xa0\xe7\xf1\xc4\x18\xfd\x78\x69\xed\x58\xd2\xaf\xa2\x63\xa4\xef\x07\xe0\xcc\x35\x00\x5a\x2d\xf8\xc5\x8c\xfd\xe9\x18\x04\x4f\x8d\x84\x12\xf5\x5c\x0a\xa8\xc2\xb4\xf0\x69\x8f\x64\x8d\x31\x41\x69\xc6\x85\xa7\x69\xa6\x90\x56\x5f\x30\x09\x3c\x56\xf0\xf1\x13\x17\xba\x67\x2c\x62\x3a\x5c\xe0\xbd\xf6\x4d\x0c\x14\x5d\xc0\xb4\x2f\xfb\xc0\x3a\xc1\x09\x67\x38\x86\x97\x8d\x48\x8b\x32\x91\xf0\xeb\xa3\x25\xfd\xec\x7b\x33\x47\x61\x83\x23\x6b\x04\x77\x36\x13\x1c\x64\x4b\xbf\x5b\xdf\x6e\x8d\x93\xa9\x0e\xcf\x29\x8a\x13\xbf\x5f\x42\x4c\x9e\x1f\x41\xc2\x78\x8a\x31\xa8\x88\x09\xc1\xc5\x35\xa9\x4a\x7a\x65\xe0\x0a\x7c\x04\x2f\x16\x7d\x63\x35\xf2\xb1\x67\x05\x8c\xad\x83\x48\x75\x0a\xe4\xa1\x1a\x6b\x49\x33\x14\xb1\x7d\xd9\x08\x39\x3f\x28\x43\x9f\x27\x20\x32\x5d\x8e\x19\x9a\xc8\xe7\xa2\xd8\x41\xee\xa0\xe1\x59\xd0\xda\x2e\xcd\xd6\x1a\x24\xbc\x56\x10\x3b\xc6\x33\x9e\x1b\x47\x4c\xf8\x2f\x79\xfc\x4c\xb6\x92\xc8\x62\x52\x94\xc7\x1d\x76\x71\xa3\xdf\xa3\x30\x3a\x06\x36\x9b\xa1\x88\x7d\x1e\xab\x01\xf0\x38\xe8\x95\x9b\xa4\x11\x34\xea\x8e\xeb\x68\x02\x82\x84\x4e\x51\x50\xef\xe0\x17\x23\x63\xc4\x14\x82\x80\xe3\x63\x38\x3c\xea\x6d\x29\xb1\xeb\x44\x63\x76\x93\xca\xe0\x8e\xeb\x49\x2d\x7e\x07\x40\xd4\xcb\xfe\x0a\xaf\xb7\x5e\x75\x9a\x49\x04\x3d\x61\x02\x48\xbd\x86\x0c\x66\x65\x4a\x99\x8a\x5e\x7c\x41\x84\xbc\x8d\x4e\x3c\xa9\x6c\x63\xec\x61\x7d\xd8\x25\x9a\xe0\xe9\x32\x1a\x11\x81\x20\xab\xeb\x09\x4a\xfc\x99\xf2\xf3\x14\xf5\x84\x5c\xa9\x33\xb0\x29\x78\x00\x4a\x33\xa9\x81\x81\x96\x4c\x28\x16\x69\x9e\x89\x10\x4c\xf2\xf6\x08\x70\x9c\x4d\xd9\x81\x4c\x1f\xee\x09\x96\x6a\x08\xdb\x10\x86\xca\x68\x08\xdf\x72\x4c\x63\x65\x95\x25\x90\xf1\xad\x7e\xca\xa4\x9a\x4b\x54\xf3\x94\x10\xc7\x2b\x33\x9f\x4d\x41\xbf\x1b\xc9\x57\x24\x89\xf0\x5f\xa4\xac\xc9\x25\x43\x31\x14\x5a\x75\xa5\xaa\x76\x26\xa2\x38\xa5\x74\x45\x29\xc6\x0b\x8a\xa8\xb6\xe9\x60\xef\xf3\x00\xf6\x12\xcb\x4e\x5c\x69\x4b\x1d\x32\x09\xbe\xd9\xdf\x49\x38\x9c\x4e\xe7\xda\x08\x41\x4f\x56\xca\x33\x4c\xd8\x3c\xd5\xc5\x18\x32\xd3\x82\xa5\x73\xec\x32\x29\x3d\x27\xe1\x58\xcb\x79\xa4\xcd\x4a\x90\xe7\xbf\x14\xdd\x1b\x5b\xb8\x32\x5f\x12\x0e\xd5\xdf\xc6\xa3\x8b\x72\x76\x32\x54\x52\xb9\xec\xdf\x2a\x13\xe1\x3b\x26\xd5\x84\xa5\xfe\xbe\x99\x27\x28\xba\x2d\x7b\xcb\x5b\x85\x0d\xc6\x65\xe6\xbf\x7a\x0d\xe3\x8c\x70\x8c\x9d\x34\x60\x2f\x69\x5a\xf6\x6a\x9e\x04\xb5\xd8\x0e\x68\x6d\x3f\x55\x43\x89\x06\xf0\x78\x5d\x69\xa9\x23\x33\xd1\xac\x25\x87\x4c\xaa\x4d\x5a\xe2\x7a\xe1\xc7\x0b\x9e\xa6\xe4\xc6\x82\x30\xd9\x45\xcc\xd2\x9d\x2b\xdb\x3f\x6b\x9f\x7c\x78\x98\x61\x78\x31\x9f\xa2\xe4\x51\x25\xc9\x3a\xc7\xb3\x38\xde\xdc\xf7\x95\xcd\x4e\xe2\x78\x6b\x9b\x75\x1b\xc9\x91\xdd\x51\xbd\x6c\x24\xd1\x37\x33\x63\x3b\x9c\x3c\x6f\x7f\xb3\x81\xff\x77\x5c\x88\x59\x8d\xcc\x6d\xa0\x38\x53\x6d\xea\xc9\xd6\x3c\xae\x8a\xcd\xd8\xdb\x74\xca\x25\xe1\xda\x81\xb7\xf4\xa2\x0e\x88\xfa\xed\xf2\x93\x35\xf8\x68\x46\x80\xcb\x52\x07\x20\x96\x48\x52\x8a\x4c\x76\x05\x48\x1b\x0e\x5a\x91\xbf\xc6\xa7\x9b\x1a\xd3\x66\x95\x15\xf6\x23\xbc\xb6\x11\x6a\x85\xa3\xb8\x7f\xc2\x1a\xae\x6d\xbb\xf6\xb4\xfb\xec\xe0\xc5\xc5\x3c\x4d\xbf\x1c\xff\x41\xbd\x43\x1b\x73\x35\x59\x4b\x02\x3f\x95\x33\x9f\x4f\x67\xfa\xa1\x60\xbd\x6d\xe2\x5e\xf6\xa9\x78\xbb\x4b\xbc\xf4\x7d\x78\x7e\x8f\x51\x07\x4b\x7f\x29\x71\x63\xd6\x2a\xb3\x34\xbd\x62\xd1\x8d\x5f\xa4\xde\x8a\x66\xb9\xd4\xc0\x64\xce\xf3\xf8\x1a\x95\x21\x8a\x07\xfb\x80\x42\x1b\xa6\x91\xcd\x35\x24\x26\x49\x11\xee\xda\x77\x80\xa6\xa7\xcd\xe8\xc6\x69\xed\xfc\xda\xa4\x0c\x8d\xc4\x87\x36\xf1\x95\x8b\x39\xec\x1f\xc3\x77\x6f\xde\xd5\xf4\x93\x68\x4a\x3b\x70\x25\x4e\xb3\x05\xc6\x8e\xdf\xb1\xf4\x7b\x00\xbf\x96\x6c\xc6\xcc\xb8\xc7\x9c\x52\x7b\xef\x8a\x1e\x5e\xd7\xb5\x33\x1a\xe2\xbc\x40\x59\x51\x63\x06\x55\x87\xbd\x2b\xa8\x46\x3a\xb1\x82\xc4\x45\x8f\x8e\x61\xca\x6e\xd0\x37\xa5\xcd\x60\x6b\x21\x6d\xf4\x50\x41\x84\x3c\x5e\x5d\x21\xae\x99\xc2\xdd\xa2\x1a\xa7\xb3\x94\xe9\xce\x93\x90\x83\x28\x23\xfd\x34\x8f\xfb\x64\xf4\x57\x65\xc0\x63\x83\x51\xa3\xa1\xd4\x68\xc9\x62\x89\x33\xed\xea\xf2\x36\x0d\xcf\x30\xc5\x0e\x82\x44\xcf\x68\x69\x92\xbb\x45\x42\xbb\xd4\x46\xbc\x09\xc3\xf7\x7f\x77\xc6\x7e\xb4\xbe\xc8\xf3\x4f\x35\x83\xda\x75\xba\x2b\x3b\x1d\xb6\xe6\x73\x36\xdd\x4e\xbb\x6e\xf3\x6d\xd7\x4a\xec\x18\x8e\x31\x4d\x2e\x31\x29\x37\x1d\xc5\xbf\xd9\x60\x0a\xd3\x04\x24\x55\xd6\x28\x22\x34\x3b\xcd\x74\xf8\x30\x3a\x1b\x1d\xc1\x5c\x21\x8c\x2e\xcb\x93\x33\x53\x65\xb0\xab\x6c\x81\x25\xc9\x6e\xfb\x70\x07\x17\xee\x6c\xf4\x96\xcd\x77\x8e\x89\xb6\x13\x1b\x5e\xdc\xd1\x8f\xdb\x78\xb2\x3b\x27\x37\x0a\x69\xeb\xe2\xd1\x33\x61\xda\x8f\x8c\x3e\x2b\xca\xb3\xf5\xa1\xbb\x2e\xa3\x63\x68\x0f\x14\x9f\x0e\x5a\x4b\xe3\x37\x83\x2b\xb4\x5c\x7e\x59\x09\x7a\xdb\xae\x20\xbf\x17\xc0\x6a\x1d\x0f\x19\x24\x1a\xbd\x19\x51\xa1\xfa\xee\xcd\xa8\x02\x9d\x55\x44\x73\x6d\x24\x7d\x8f\xde\xde\xca\x49\xdf\x89\x8f\x56\x27\x15\xf2\xd4\xaa\xa4\xb2\x2a\x57\x3c\xc9\x05\x4f\xf5\xc1\xf3\x6d\xb9\x66\x32\xd8\x2d\x17\x6c\x91\x0a\xd6\x66\x02\xa7\x24\xe8\x82\x6b\xab\x5a\xb3\x0a\x73\x60\xbf\xf0\x2a\x13\x31\x75\xfb\x5d\xf0\xdb\x39\x3e\xc5\xc7\x3c\x69\x9f\x8b\x9a\x73\xc9\x8d\x83\x6d\xd5\x39\x65\xc4\xc4\xcf\x1a\x52\x2e\x6e\x8c\x0c\x54\x18\xc0\x1f\x7d\xab\x54\xb1\xd1\xff\xe8\x83\xce\xe0\x45\x0c\x26\x1f\x44\xa8\xc0\xff\x15\x5e\x07\xfd\x01\x88\xc0\x0d\xe0\x2f\xa6\xa5\x2e\x53\xed\x9a\x8f\x9e\x0b\x7e\x4c\xf0\x6f\x1e\xb7\x94\xf2\xaa\x91\x75\xf8\x9f\xff\xb6\xf1\xd1\xe2\xc7\xc3\x4f\x41\x10\x7e\xcb\x78\x7f\x36\xd8\xd8\xce\x74\x85\xee\xab\xad\xb7\x6d\x8a\x0d\xc2\x13\x11\xfb\x41\x38\x54\x5b\x81\xd7\x37\x36\x3e\x4b\x12\x8c\x34\xc6\xd5\xd9\xac\x44\x65\x3e\x0f\x9e\x14\x0d\x2d\xc1\x76\x5e\x90\x27\xc0\x85\xf6\xcb\x75\x03\xf8\xcb\x16\x78\xb6\xf1\xb2\x2f\xcf\xa5\x34\x56\x96\x8c\x0b\xfd\xd6\x7c\x2d\x7a\x9c\xaa\xeb\x23\x83\x40\xe3\x99\xe4\x42\x27\x7e\x7f\x19\x62\xfc\x17\x8b\x00\x58\x2a\x91\xc5\x0f\x10\x65\x42\x18\x29\x09\x79\x18\xc4\x3c\x31\x80\xa8\x0b\x68\xaa\x87\xf5\x6d\x04\xe4\x0d\x55\xeb\xb3\x9d\x9a\xc5\x53\x65\x56\x9e\x03\x98\xe3\x25\x97\x8b\x17\x6c\xfc\x70\x50\xc1\x6b\x4d\xb4\x3f\x53\xc4\xd6\x98\x46\xf4\xb7\x30\xc6\x4e\x78\xf7\x64\xc0\x2b\xa5\xaf\x38\xb8\x7d\x1e\xd8\x6f\xb5\x8f\x3c\x36\x16\xc9\x07\xd0\xc5\x27\x6c\x1f\xa4\x4e\x3c\x76\x3e\xb6\x9b\x1c\x44\xa9\xe7\x95\xc4\x04\x22\x89\xe6\xdb\x36\x15\xa7\xf6\xa4\x88\x0b\xb8\xca\xf4\x04\xee\xd8\x83\x72\x8b\xd4\xf6\x69\xf7\xf3\x9f\xd9\x38\x17\x3d\x2c\xbf\x50\x28\x57\x81\xcd\x2a\x80\x2a\xee\x1e\x6c\x5b\xa9\x6e\x55\x28\x37\x02\x66\x51\xc7\x44\xe1\xad\xc7\xe6\x61\xe5\x3f\xcd\x5b\x7f\xf1\xf1\xf0\xd3\x00\x16\x1f\x5f\x7f\x5a\x53\x3f\x75\x1c\x31\x7e\x55\x62\xba\xb4\x91\x46\xa5\x6f\xfe\xdc\x09\xff\xc9\xf9\x7e\xb7\xaf\x89\xdf\x03\xd3\xed\xf2\x6b\x7d\xcc\xf1\x05\xd8\x9b\x95\x66\x7f\x5f\x4a\xff\x8d\x80\x70\x16\x8e\xa4\x1f\x3c\x99\x35\xac\xa4\x42\x5f\x2f\xaa\x3a\x83\x8a\xc8\xcc\x6c\x60\xd1\x6e\x4b\x46\xf3\x5d\x04\xd7\x0f\xce\x6c\x32\x81\x90\x25\x1d\x35\xd4\x8b\xc5\x93\xe8\xcd\x0d\x3e\xa8\xcd\x54\x59\xcb\x82\x9c\x3a\xb3\x4a\xdf\xeb\xf7\x79\x75\x21\xa3\xdc\x41\xce\xed\xa6\xc2\x66\x86\x48\xa8\xc2\xcb\x4a\x4b\xda\xa9\xe1\x89\xce\xb8\xbf\xb9\xd4\x54\x0b\xd4\x67\xbf\xea\x79\x0e\x75\x3b\xbe\x4d\x16\x00\xb5\x95\x60\xce\x5c\x1d\xb7\x0a\x9a\x74\xa6\x58\xe6\xcf\x5a\x8f\x3e\xb9\x88\x2a\x17\x6d\x40\xce\xb2\xf9\xbf\x91\x5d\xd6\x9a\xe5\xab\x15\x9a\xab\x6d\xe4\x84\xd5\xff\x60\xfa\x07\x87\xe9\x32\x16\x5a\x37\xf6\xaa\x9b\xc0\xfa\x3e\x3c\xcd\xa6\x53\xae\xfd\xed\x2e\xf8\xd6\x6d\xcd\x4b\xe7\xed\xdb\xe6\x76\xbf\x96\x15\xb0\x73\xfb\x5b\xf0\xb4\x67\xef\xed\x97\x37\xd2\xd7\x5e\xe1\x77\x09\x5b\xee\xde\xec\xeb\x4e\x24\xab\x93\x48\xc1\xd2\xba\xd2\x82\xb5\x48\xc3\xf1\xaa\x0c\xb8\x4a\xdf\x83\x7d\x28\x7e\x73\x65\x2e\x72\xdd\x88\xbb\x4c\x00\xd3\xf6\x9f\x26\xcc\x32\x2e\x74\x55\xcd\xb6\x6e\x53\xd8\xfb\xb9\xb5\xc4\xf6\x92\x6e\xaf\xca\x23\x14\xc9\x56\x3e\xc7\x57\xb5\x85\xfe\x1b\x00\x00\xff\xff\x3a\x5e\x2d\x9f\xa8\x31\x00\x00") func templateDialectSqlUpdateTmplBytes() ([]byte, error) { return bindataRead( @@ -732,7 +732,7 @@ func templateDialectSqlUpdateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/update.tmpl", size: 12590, mode: os.FileMode(420), modTime: time.Unix(1568799587, 0)} + info := bindataFileInfo{name: "template/dialect/sql/update.tmpl", size: 12712, mode: os.FileMode(420), modTime: time.Unix(1569235109, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/dialect/sql/create.tmpl b/entc/gen/template/dialect/sql/create.tmpl index 7899ecb56..e6ba84a93 100644 --- a/entc/gen/template/dialect/sql/create.tmpl +++ b/entc/gen/template/dialect/sql/create.tmpl @@ -40,7 +40,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 }}int(id){{ end }} + {{ $.Receiver }}.ID = {{ if $.ID.IsString }}strconv.FormatInt(id, 10){{ else }}{{ $.ID.Type }}(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/update.tmpl b/entc/gen/template/dialect/sql/update.tmpl index 25e479ce3..0398c0360 100644 --- a/entc/gen/template/dialect/sql/update.tmpl +++ b/entc/gen/template/dialect/sql/update.tmpl @@ -35,7 +35,7 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) ({{ $ret }} if err := {{ $.Receiver }}.FromRows(rows); err != nil { return {{ $zero }}, fmt.Errorf("{{ $pkg }}: failed scanning row into {{ $.Name }}: %v", err) } - id = {{ $.Receiver }}.{{- if $.ID.IsString }}id(){{ else }}ID{{ end }} + id = {{ if $.ID.IsString }}{{ $.Receiver }}.id(){{ else if not $.ID.IsInt }}int({{ $.Receiver }}.ID){{ else }}{{ $.Receiver }}.ID{{ end }} {{- else }} if err := rows.Scan(&id); err != nil { return {{ $zero }}, fmt.Errorf("{{ $pkg }}: failed reading id: %v", err) @@ -311,5 +311,7 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) ({{ $ret }} err = rollback(tx, serr) return {{/* return is not knwon at this point. */}} } + {{- else if not $.Type.ID.IsInt }} + eid := int(eid) {{- end }} {{ end }} diff --git a/entc/gen/type.go b/entc/gen/type.go index dec7c74e1..160669ce1 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -413,6 +413,9 @@ func (f Field) IsJSON() bool { return f.Type != nil && f.Type.Type == field.Type // IsString returns true if the field is a string field. func (f Field) IsString() bool { return f.Type != nil && f.Type.Type == field.TypeString } +// IsInt returns true if the field is an int field. +func (f Field) IsInt() bool { return f.Type != nil && f.Type.Type == field.TypeInt } + // NullType returns the sql null-type for optional and nullable fields. func (f Field) NullType() string { switch f.Type.Type { diff --git a/entc/integration/config/config_test.go b/entc/integration/config/config_test.go index bb079ac21..04915d9cc 100644 --- a/entc/integration/config/config_test.go +++ b/entc/integration/config/config_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestCustomTemplate(t *testing.T) { +func TestSchemaConfig(t *testing.T) { drv, err := sql.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") require.NoError(t, err) defer drv.Close() diff --git a/entc/integration/generate.go b/entc/integration/generate.go index 41b6ed25e..fe56ed829 100644 --- a/entc/integration/generate.go +++ b/entc/integration/generate.go @@ -10,3 +10,4 @@ package integration //go:generate go run ../cmd/entc/entc.go generate --header "Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.\n// This source code is licensed under the Apache 2.0 license found\n// in the LICENSE file in the root directory of this source tree.\n\n// Code generated (@generated) by entc, DO NOT EDIT." ./template/ent/schema --template=template/ent/template //go:generate go run ../cmd/entc/entc.go generate --header "Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.\n// This source code is licensed under the Apache 2.0 license found\n// in the LICENSE file in the root directory of this source tree.\n\n// Code generated (@generated) by entc, DO NOT EDIT." ./json/ent/schema //go:generate go run ../cmd/entc/entc.go generate --header "Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.\n// This source code is licensed under the Apache 2.0 license found\n// in the LICENSE file in the root directory of this source tree.\n\n// Code generated (@generated) by entc, DO NOT EDIT." ./config/ent/schema +//go:generate go run ../cmd/entc/entc.go generate --header "Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.\n// This source code is licensed under the Apache 2.0 license found\n// in the LICENSE file in the root directory of this source tree.\n\n// Code generated (@generated) by entc, DO NOT EDIT." --idtype uint64 ./idtype/ent/schema diff --git a/entc/integration/idtype/ent/client.go b/entc/integration/idtype/ent/client.go new file mode 100644 index 000000000..567e5bc9e --- /dev/null +++ b/entc/integration/idtype/ent/client.go @@ -0,0 +1,189 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "log" + + "github.com/facebookincubator/ent/entc/integration/idtype/ent/migrate" + + "github.com/facebookincubator/ent/entc/integration/idtype/ent/user" + + "github.com/facebookincubator/ent/dialect" + "github.com/facebookincubator/ent/dialect/sql" +) + +// Client is the client that holds all ent builders. +type Client struct { + config + // Schema is the client for creating, migrating and dropping schema. + Schema *migrate.Schema + // User is the client for interacting with the User builders. + User *UserClient +} + +// NewClient creates a new client configured with the given options. +func NewClient(opts ...Option) *Client { + c := config{log: log.Println} + c.options(opts...) + return &Client{ + config: c, + Schema: migrate.NewSchema(c.driver), + User: NewUserClient(c), + } +} + +// Tx returns a new transactional client. +func (c *Client) Tx(ctx context.Context) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") + } + tx, err := newTx(ctx, c.driver) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %v", err) + } + cfg := config{driver: tx, log: c.log, debug: c.debug} + return &Tx{ + config: cfg, + User: NewUserClient(cfg), + }, nil +} + +// Debug returns a new debug-client. It's used to get verbose logging on specific operations. +// +// client.Debug(). +// User. +// Query(). +// Count(ctx) +// +func (c *Client) Debug() *Client { + if c.debug { + return c + } + cfg := config{driver: dialect.Debug(c.driver, c.log), log: c.log, debug: true} + return &Client{ + config: cfg, + Schema: migrate.NewSchema(cfg.driver), + User: NewUserClient(cfg), + } +} + +// UserClient is a client for the User schema. +type UserClient struct { + config +} + +// NewUserClient returns a client for the User from the given config. +func NewUserClient(c config) *UserClient { + return &UserClient{config: c} +} + +// Create returns a create builder for User. +func (c *UserClient) Create() *UserCreate { + return &UserCreate{config: c.config} +} + +// Update returns an update builder for User. +func (c *UserClient) Update() *UserUpdate { + return &UserUpdate{config: c.config} +} + +// UpdateOne returns an update builder for the given entity. +func (c *UserClient) UpdateOne(u *User) *UserUpdateOne { + return c.UpdateOneID(u.ID) +} + +// UpdateOneID returns an update builder for the given id. +func (c *UserClient) UpdateOneID(id uint64) *UserUpdateOne { + return &UserUpdateOne{config: c.config, id: id} +} + +// Delete returns a delete builder for User. +func (c *UserClient) Delete() *UserDelete { + return &UserDelete{config: c.config} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *UserClient) DeleteOne(u *User) *UserDeleteOne { + return c.DeleteOneID(u.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *UserClient) DeleteOneID(id uint64) *UserDeleteOne { + return &UserDeleteOne{c.Delete().Where(user.ID(id))} +} + +// Create returns a query builder for User. +func (c *UserClient) Query() *UserQuery { + return &UserQuery{config: c.config} +} + +// Get returns a User entity by its id. +func (c *UserClient) Get(ctx context.Context, id uint64) (*User, error) { + return c.Query().Where(user.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *UserClient) GetX(ctx context.Context, id uint64) *User { + u, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return u +} + +// QuerySpouse queries the spouse edge of a User. +func (c *UserClient) QuerySpouse(u *User) *UserQuery { + query := &UserQuery{config: c.config} + id := u.ID + query.sql = sql.Select().From(sql.Table(user.Table)). + Where(sql.EQ(user.SpouseColumn, id)) + + return query +} + +// QueryFollowers queries the followers edge of a User. +func (c *UserClient) QueryFollowers(u *User) *UserQuery { + query := &UserQuery{config: c.config} + id := u.ID + t1 := sql.Table(user.Table) + t2 := sql.Table(user.Table) + t3 := sql.Table(user.FollowersTable) + t4 := sql.Select(t3.C(user.FollowersPrimaryKey[0])). + From(t3). + Join(t2). + On(t3.C(user.FollowersPrimaryKey[1]), t2.C(user.FieldID)). + Where(sql.EQ(t2.C(user.FieldID), id)) + query.sql = sql.Select(). + From(t1). + Join(t4). + On(t1.C(user.FieldID), t4.C(user.FollowersPrimaryKey[0])) + + return query +} + +// QueryFollowing queries the following edge of a User. +func (c *UserClient) QueryFollowing(u *User) *UserQuery { + query := &UserQuery{config: c.config} + id := u.ID + t1 := sql.Table(user.Table) + t2 := sql.Table(user.Table) + t3 := sql.Table(user.FollowingTable) + t4 := sql.Select(t3.C(user.FollowingPrimaryKey[1])). + From(t3). + Join(t2). + On(t3.C(user.FollowingPrimaryKey[0]), t2.C(user.FieldID)). + Where(sql.EQ(t2.C(user.FieldID), id)) + query.sql = sql.Select(). + From(t1). + Join(t4). + On(t1.C(user.FieldID), t4.C(user.FollowingPrimaryKey[1])) + + return query +} diff --git a/entc/integration/idtype/ent/config.go b/entc/integration/idtype/ent/config.go new file mode 100644 index 000000000..1a5d585d1 --- /dev/null +++ b/entc/integration/idtype/ent/config.go @@ -0,0 +1,55 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "github.com/facebookincubator/ent/dialect" +) + +// Option function to configure the client. +type Option func(*config) + +// Config is the configuration for the client and its builder. +type config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...interface{}) +} + +// Options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...interface{})) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} diff --git a/entc/integration/idtype/ent/context.go b/entc/integration/idtype/ent/context.go new file mode 100644 index 000000000..c6a16805e --- /dev/null +++ b/entc/integration/idtype/ent/context.go @@ -0,0 +1,24 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" +) + +type contextKey struct{} + +// FromContext returns the Client stored in a context, or nil if there isn't one. +func FromContext(ctx context.Context) *Client { + c, _ := ctx.Value(contextKey{}).(*Client) + return c +} + +// NewContext returns a new context with the given Client attached. +func NewContext(parent context.Context, c *Client) context.Context { + return context.WithValue(parent, contextKey{}, c) +} diff --git a/entc/integration/idtype/ent/ent.go b/entc/integration/idtype/ent/ent.go new file mode 100644 index 000000000..ee2aeb448 --- /dev/null +++ b/entc/integration/idtype/ent/ent.go @@ -0,0 +1,196 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + + "github.com/facebookincubator/ent/dialect" + "github.com/facebookincubator/ent/dialect/sql" +) + +// Order applies an ordering on either graph traversal or sql selector. +type Order func(*sql.Selector) + +// Asc applies the given fields in ASC order. +func Asc(fields ...string) Order { + return Order( + func(s *sql.Selector) { + for _, f := range fields { + s.OrderBy(sql.Asc(f)) + } + }, + ) +} + +// Desc applies the given fields in DESC order. +func Desc(fields ...string) Order { + return Order( + func(s *sql.Selector) { + for _, f := range fields { + s.OrderBy(sql.Desc(f)) + } + }, + ) +} + +// Aggregate applies an aggregation step on the group-by traversal/selector. +type Aggregate struct { + // SQL the column wrapped with the aggregation function. + SQL func(*sql.Selector) string +} + +// As is a pseudo aggregation function for renaming another other functions with custom names. For example: +// +// GroupBy(field1, field2). +// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). +// Scan(ctx, &v) +// +func As(fn Aggregate, end string) Aggregate { + return Aggregate{ + SQL: func(s *sql.Selector) string { + return sql.As(fn.SQL(s), end) + }, + } +} + +// Count applies the "count" aggregation function on each group. +func Count() Aggregate { + return Aggregate{ + SQL: func(s *sql.Selector) string { + return sql.Count("*") + }, + } +} + +// Max applies the "max" aggregation function on the given field of each group. +func Max(field string) Aggregate { + return Aggregate{ + SQL: func(s *sql.Selector) string { + return sql.Max(s.C(field)) + }, + } +} + +// Mean applies the "mean" aggregation function on the given field of each group. +func Mean(field string) Aggregate { + return Aggregate{ + SQL: func(s *sql.Selector) string { + return sql.Avg(s.C(field)) + }, + } +} + +// Min applies the "min" aggregation function on the given field of each group. +func Min(field string) Aggregate { + return Aggregate{ + SQL: func(s *sql.Selector) string { + return sql.Min(s.C(field)) + }, + } +} + +// Sum applies the "sum" aggregation function on the given field of each group. +func Sum(field string) Aggregate { + return Aggregate{ + SQL: func(s *sql.Selector) string { + return sql.Sum(s.C(field)) + }, + } +} + +// ErrNotFound returns when trying to fetch a specific entity and it was not found in the database. +type ErrNotFound struct { + label string +} + +// Error implements the error interface. +func (e *ErrNotFound) Error() string { + return fmt.Sprintf("ent: %s not found", e.label) +} + +// IsNotFound returns a boolean indicating whether the error is a not found error. +func IsNotFound(err error) bool { + _, ok := err.(*ErrNotFound) + return ok +} + +// MaskNotFound masks nor found error. +func MaskNotFound(err error) error { + if IsNotFound(err) { + return nil + } + return err +} + +// ErrNotSingular returns when trying to fetch a singular entity and more then one was found in the database. +type ErrNotSingular struct { + label string +} + +// Error implements the error interface. +func (e *ErrNotSingular) Error() string { + return fmt.Sprintf("ent: %s not singular", e.label) +} + +// IsNotSingular returns a boolean indicating whether the error is a not singular error. +func IsNotSingular(err error) bool { + _, ok := err.(*ErrNotSingular) + return ok +} + +// ErrConstraintFailed returns when trying to create/update one or more entities and +// one or more of their constraints failed. For example, violation of edge or field uniqueness. +type ErrConstraintFailed struct { + msg string + wrap error +} + +// Error implements the error interface. +func (e ErrConstraintFailed) Error() string { + return fmt.Sprintf("ent: unique constraint failed: %s", e.msg) +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ErrConstraintFailed) Unwrap() error { + return e.wrap +} + +// IsConstraintFailure returns a boolean indicating whether the error is a constraint failure. +func IsConstraintFailure(err error) bool { + _, ok := err.(*ErrConstraintFailed) + return ok +} + +func isSQLConstraintError(err error) (*ErrConstraintFailed, bool) { + // Error number 1062 is ER_DUP_ENTRY in mysql, and "UNIQUE constraint failed" is SQLite prefix. + if msg := err.Error(); strings.HasPrefix(msg, "Error 1062") || strings.HasPrefix(msg, "UNIQUE constraint failed") { + return &ErrConstraintFailed{msg, err}, true + } + return nil, false +} + +// rollback calls to tx.Rollback and wraps the given error with the rollback error if occurred. +func rollback(tx dialect.Tx, err error) error { + if rerr := tx.Rollback(); rerr != nil { + err = fmt.Errorf("%s: %v", err.Error(), rerr) + } + if err, ok := isSQLConstraintError(err); ok { + return err + } + return err +} + +// keys returns the keys/ids from the edge map. +func keys(m map[uint64]struct{}) []uint64 { + s := make([]uint64, 0, len(m)) + for id, _ := range m { + s = append(s, id) + } + return s +} diff --git a/entc/integration/idtype/ent/example_test.go b/entc/integration/idtype/ent/example_test.go new file mode 100644 index 000000000..c1d00848f --- /dev/null +++ b/entc/integration/idtype/ent/example_test.go @@ -0,0 +1,68 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "log" + + "github.com/facebookincubator/ent/dialect/sql" +) + +// dsn for the database. In order to run the tests locally, run the following command: +// +// ENT_INTEGRATION_ENDPOINT="root:pass@tcp(localhost:3306)/test?parseTime=True" go test -v +// +var dsn string + +func ExampleUser() { + if dsn == "" { + return + } + ctx := context.Background() + drv, err := sql.Open("mysql", dsn) + if err != nil { + log.Fatalf("failed creating database client: %v", err) + } + defer drv.Close() + client := NewClient(Driver(drv)) + // creating vertices for the user's edges. + u0 := client.User. + Create(). + SetName("string"). + SaveX(ctx) + log.Println("user created:", u0) + u2 := client.User. + Create(). + SetName("string"). + SaveX(ctx) + log.Println("user created:", u2) + + // create user vertex with its edges. + u := client.User. + Create(). + SetName("string"). + SetSpouse(u0). + AddFollowing(u2). + SaveX(ctx) + log.Println("user created:", u) + + // query edges. + u0, err = u.QuerySpouse().First(ctx) + if err != nil { + log.Fatalf("failed querying spouse: %v", err) + } + log.Println("spouse found:", u0) + + u2, err = u.QueryFollowing().First(ctx) + if err != nil { + log.Fatalf("failed querying following: %v", err) + } + log.Println("following found:", u2) + + // Output: +} diff --git a/entc/integration/idtype/ent/migrate/migrate.go b/entc/integration/idtype/ent/migrate/migrate.go new file mode 100644 index 000000000..7991000b1 --- /dev/null +++ b/entc/integration/idtype/ent/migrate/migrate.go @@ -0,0 +1,71 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package migrate + +import ( + "context" + "fmt" + "io" + + "github.com/facebookincubator/ent/dialect" + "github.com/facebookincubator/ent/dialect/sql/schema" +) + +var ( + // WithGlobalUniqueID sets the universal ids options to the migration. + // If this option is enabled, ent migration will allocate a 1<<32 range + // for the ids of each entity (table). + // Note that this option cannot be applied on tables that already exist. + WithGlobalUniqueID = schema.WithGlobalUniqueID + // WithDropColumn sets the drop column option to the migration. + // If this option is enabled, ent migration will drop old columns + // that were used for both fields and edges. This defaults to false. + WithDropColumn = schema.WithDropColumn + // WithDropIndex sets the drop index option to the migration. + // If this option is enabled, ent migration will drop old indexes + // that were defined in the schema. This defaults to false. + // Note that unique constraints are defined using `UNIQUE INDEX`, + // and therefore, it's recommended to enable this option to get more + // flexibility in the schema changes. + WithDropIndex = schema.WithDropIndex +) + +// Schema is the API for creating, migrating and dropping a schema. +type Schema struct { + drv dialect.Driver + universalID bool +} + +// NewSchema creates a new schema client. +func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } + +// Create creates all schema resources. +func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { + migrate, err := schema.NewMigrate(s.drv, opts...) + if err != nil { + return fmt.Errorf("ent/migrate: %v", err) + } + return migrate.Create(ctx, Tables...) +} + +// WriteTo writes the schema changes to w instead of running them against the database. +// +// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { +// log.Fatal(err) +// } +// +func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { + drv := &schema.WriteDriver{ + Writer: w, + Driver: s.drv, + } + migrate, err := schema.NewMigrate(drv, opts...) + if err != nil { + return fmt.Errorf("ent/migrate: %v", err) + } + return migrate.Create(ctx, Tables...) +} diff --git a/entc/integration/idtype/ent/migrate/schema.go b/entc/integration/idtype/ent/migrate/schema.go new file mode 100644 index 000000000..fbbe18881 --- /dev/null +++ b/entc/integration/idtype/ent/migrate/schema.go @@ -0,0 +1,74 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package migrate + +import ( + "github.com/facebookincubator/ent/dialect/sql/schema" + "github.com/facebookincubator/ent/schema/field" +) + +var ( + // UsersColumns holds the columns for the "users" table. + UsersColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "name", Type: field.TypeString}, + {Name: "user_spouse_id", Type: field.TypeInt, Unique: true, Nullable: true}, + } + // UsersTable holds the schema information for the "users" table. + UsersTable = &schema.Table{ + Name: "users", + Columns: UsersColumns, + PrimaryKey: []*schema.Column{UsersColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "users_users_spouse", + Columns: []*schema.Column{UsersColumns[2]}, + + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } + // UserFollowingColumns holds the columns for the "user_following" table. + UserFollowingColumns = []*schema.Column{ + {Name: "user_id", Type: field.TypeInt}, + {Name: "follower_id", Type: field.TypeInt}, + } + // UserFollowingTable holds the schema information for the "user_following" table. + UserFollowingTable = &schema.Table{ + Name: "user_following", + Columns: UserFollowingColumns, + PrimaryKey: []*schema.Column{UserFollowingColumns[0], UserFollowingColumns[1]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "user_following_user_id", + Columns: []*schema.Column{UserFollowingColumns[0]}, + + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "user_following_follower_id", + Columns: []*schema.Column{UserFollowingColumns[1]}, + + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.Cascade, + }, + }, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + UsersTable, + UserFollowingTable, + } +) + +func init() { + UsersTable.ForeignKeys[0].RefTable = UsersTable + UserFollowingTable.ForeignKeys[0].RefTable = UsersTable + UserFollowingTable.ForeignKeys[1].RefTable = UsersTable +} diff --git a/entc/integration/idtype/ent/predicate/predicate.go b/entc/integration/idtype/ent/predicate/predicate.go new file mode 100644 index 000000000..1226d0823 --- /dev/null +++ b/entc/integration/idtype/ent/predicate/predicate.go @@ -0,0 +1,14 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package predicate + +import ( + "github.com/facebookincubator/ent/dialect/sql" +) + +// User is the predicate function for user builders. +type User func(*sql.Selector) diff --git a/entc/integration/idtype/ent/schema/user.go b/entc/integration/idtype/ent/schema/user.go new file mode 100644 index 000000000..a2d34414e --- /dev/null +++ b/entc/integration/idtype/ent/schema/user.go @@ -0,0 +1,33 @@ +// Copyright 2019-present Facebook Inc. All rights reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +package schema + +import ( + "github.com/facebookincubator/ent" + "github.com/facebookincubator/ent/schema/edge" + "github.com/facebookincubator/ent/schema/field" +) + +// User holds the schema definition for the User entity. +type User struct { + ent.Schema +} + +// Fields of the User. +func (User) Fields() []ent.Field { + return []ent.Field{ + field.String("name"), + } +} + +// Edges of the User. +func (User) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("spouse", User.Type). + Unique(), + edge.To("following", User.Type). + From("followers"), + } +} diff --git a/entc/integration/idtype/ent/tx.go b/entc/integration/idtype/ent/tx.go new file mode 100644 index 000000000..01bb1d6af --- /dev/null +++ b/entc/integration/idtype/ent/tx.go @@ -0,0 +1,97 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + + "github.com/facebookincubator/ent/dialect" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/migrate" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // User is the client for interacting with the User builders. + User *UserClient +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + return tx.config.driver.(*txDriver).tx.Commit() +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + return tx.config.driver.(*txDriver).tx.Rollback() +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + return &Client{ + config: tx.config, + Schema: migrate.NewSchema(tx.driver), + User: NewUserClient(tx.config), + } +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: User.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that txDriver is not goroutine safe. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // tx is the underlying transaction. + tx dialect.Tx +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error { + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error { + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil) diff --git a/entc/integration/idtype/ent/user.go b/entc/integration/idtype/ent/user.go new file mode 100644 index 000000000..c198cc663 --- /dev/null +++ b/entc/integration/idtype/ent/user.go @@ -0,0 +1,105 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "bytes" + "fmt" + + "github.com/facebookincubator/ent/dialect/sql" +) + +// User is the model entity for the User schema. +type User struct { + config `json:"-"` + // ID of the ent. + ID uint64 `json:"id,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` +} + +// FromRows scans the sql response data into User. +func (u *User) FromRows(rows *sql.Rows) error { + var vu struct { + ID uint64 + Name sql.NullString + } + // the order here should be the same as in the `user.Columns`. + if err := rows.Scan( + &vu.ID, + &vu.Name, + ); err != nil { + return err + } + u.ID = vu.ID + u.Name = vu.Name.String + return nil +} + +// QuerySpouse queries the spouse edge of the User. +func (u *User) QuerySpouse() *UserQuery { + return (&UserClient{u.config}).QuerySpouse(u) +} + +// QueryFollowers queries the followers edge of the User. +func (u *User) QueryFollowers() *UserQuery { + return (&UserClient{u.config}).QueryFollowers(u) +} + +// QueryFollowing queries the following edge of the User. +func (u *User) QueryFollowing() *UserQuery { + return (&UserClient{u.config}).QueryFollowing(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. +func (u *User) Update() *UserUpdateOne { + return (&UserClient{u.config}).UpdateOne(u) +} + +// Unwrap unwraps the entity that was returned from a transaction after it was closed, +// so that all next queries will be executed through the driver which created the transaction. +func (u *User) Unwrap() *User { + tx, ok := u.config.driver.(*txDriver) + if !ok { + panic("ent: User is not a transactional entity") + } + u.config.driver = tx.drv + return u +} + +// String implements the fmt.Stringer. +func (u *User) String() string { + buf := bytes.NewBuffer(nil) + buf.WriteString("User(") + buf.WriteString(fmt.Sprintf("id=%v", u.ID)) + buf.WriteString(fmt.Sprintf(", name=%v", u.Name)) + buf.WriteString(")") + return buf.String() +} + +// Users is a parsable slice of User. +type Users []*User + +// FromRows scans the sql response data into Users. +func (u *Users) FromRows(rows *sql.Rows) error { + for rows.Next() { + vu := &User{} + if err := vu.FromRows(rows); err != nil { + return err + } + *u = append(*u, vu) + } + return nil +} + +func (u Users) config(cfg config) { + for i := range u { + u[i].config = cfg + } +} diff --git a/entc/integration/idtype/ent/user/user.go b/entc/integration/idtype/ent/user/user.go new file mode 100644 index 000000000..ac0fa7000 --- /dev/null +++ b/entc/integration/idtype/ent/user/user.go @@ -0,0 +1,42 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package user + +const ( + // Label holds the string label denoting the user type in the database. + Label = "user" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldName holds the string denoting the name vertex property in the database. + FieldName = "name" + + // Table holds the table name of the user in the database. + Table = "users" + // SpouseTable is the table the holds the spouse relation/edge. + SpouseTable = "users" + // SpouseColumn is the table column denoting the spouse relation/edge. + SpouseColumn = "user_spouse_id" + // FollowersTable is the table the holds the followers relation/edge. The primary key declared below. + FollowersTable = "user_following" + // FollowingTable is the table the holds the following relation/edge. The primary key declared below. + FollowingTable = "user_following" +) + +// Columns holds all SQL columns are user fields. +var Columns = []string{ + FieldID, + FieldName, +} + +var ( + // FollowersPrimaryKey and FollowersColumn2 are the table columns denoting the + // primary key for the followers relation (M2M). + FollowersPrimaryKey = []string{"user_id", "follower_id"} + // FollowingPrimaryKey and FollowingColumn2 are the table columns denoting the + // primary key for the following relation (M2M). + FollowingPrimaryKey = []string{"user_id", "follower_id"} +) diff --git a/entc/integration/idtype/ent/user/where.go b/entc/integration/idtype/ent/user/where.go new file mode 100644 index 000000000..7c609bf9c --- /dev/null +++ b/entc/integration/idtype/ent/user/where.go @@ -0,0 +1,396 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package user + +import ( + "github.com/facebookincubator/ent/dialect/sql" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/predicate" +) + +// ID filters vertices based on their identifier. +func ID(id uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }, + ) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }, + ) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldID), id)) + }, + ) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldID), id)) + }, + ) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldID), id)) + }, + ) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldID), id)) + }, + ) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldID), id)) + }, + ) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.In(s.C(FieldID), v...)) + }, + ) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uint64) predicate.User { + return predicate.User( + func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }, + ) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldName), v)) + }, + ) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldName), v)) + }, + ) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldName), v)) + }, + ) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldName), v)) + }, + ) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldName), v)) + }, + ) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldName), v)) + }, + ) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldName), v)) + }, + ) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.User { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.User( + func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(vs) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldName), v...)) + }, + ) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.User { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.User( + func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(vs) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldName), v...)) + }, + ) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldName), v)) + }, + ) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldName), v)) + }, + ) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldName), v)) + }, + ) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldName), v)) + }, + ) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.User { + return predicate.User( + func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldName), v)) + }, + ) +} + +// HasSpouse applies the HasEdge predicate on the "spouse" edge. +func HasSpouse() predicate.User { + return predicate.User( + func(s *sql.Selector) { + t1 := s.Table() + s.Where( + sql.In( + t1.C(FieldID), + sql.Select(SpouseColumn). + From(sql.Table(SpouseTable)). + Where(sql.NotNull(SpouseColumn)), + ), + ) + }, + ) +} + +// HasSpouseWith applies the HasEdge predicate on the "spouse" edge with a given conditions (other predicates). +func HasSpouseWith(preds ...predicate.User) predicate.User { + return predicate.User( + func(s *sql.Selector) { + t1 := s.Table() + t2 := sql.Select(SpouseColumn).From(sql.Table(SpouseTable)) + for _, p := range preds { + p(t2) + } + s.Where(sql.In(t1.C(FieldID), t2)) + }, + ) +} + +// HasFollowers applies the HasEdge predicate on the "followers" edge. +func HasFollowers() predicate.User { + return predicate.User( + func(s *sql.Selector) { + t1 := s.Table() + s.Where( + sql.In( + t1.C(FieldID), + sql.Select(FollowersPrimaryKey[1]).From(sql.Table(FollowersTable)), + ), + ) + }, + ) +} + +// HasFollowersWith applies the HasEdge predicate on the "followers" edge with a given conditions (other predicates). +func HasFollowersWith(preds ...predicate.User) predicate.User { + return predicate.User( + func(s *sql.Selector) { + t1 := s.Table() + t2 := sql.Table(Table) + t3 := sql.Table(FollowersTable) + t4 := sql.Select(t3.C(FollowersPrimaryKey[1])). + From(t3). + Join(t2). + On(t3.C(FollowersPrimaryKey[0]), t2.C(FieldID)) + t5 := sql.Select().From(t2) + for _, p := range preds { + p(t5) + } + t4.FromSelect(t5) + s.Where(sql.In(t1.C(FieldID), t4)) + }, + ) +} + +// HasFollowing applies the HasEdge predicate on the "following" edge. +func HasFollowing() predicate.User { + return predicate.User( + func(s *sql.Selector) { + t1 := s.Table() + s.Where( + sql.In( + t1.C(FieldID), + sql.Select(FollowingPrimaryKey[0]).From(sql.Table(FollowingTable)), + ), + ) + }, + ) +} + +// HasFollowingWith applies the HasEdge predicate on the "following" edge with a given conditions (other predicates). +func HasFollowingWith(preds ...predicate.User) predicate.User { + return predicate.User( + func(s *sql.Selector) { + t1 := s.Table() + t2 := sql.Table(Table) + t3 := sql.Table(FollowingTable) + t4 := sql.Select(t3.C(FollowingPrimaryKey[0])). + From(t3). + Join(t2). + On(t3.C(FollowingPrimaryKey[1]), t2.C(FieldID)) + t5 := sql.Select().From(t2) + for _, p := range preds { + p(t5) + } + t4.FromSelect(t5) + s.Where(sql.In(t1.C(FieldID), t4)) + }, + ) +} + +// 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) { + for _, p := range predicates { + p(s) + } + }, + ) +} + +// Or groups list of predicates with the OR operator between them. +func Or(predicates ...predicate.User) predicate.User { + return predicate.User( + func(s *sql.Selector) { + for i, p := range predicates { + if i > 0 { + s.Or() + } + p(s) + } + }, + ) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.User) predicate.User { + return predicate.User( + func(s *sql.Selector) { + p(s.Not()) + }, + ) +} diff --git a/entc/integration/idtype/ent/user_create.go b/entc/integration/idtype/ent/user_create.go new file mode 100644 index 000000000..17726caa2 --- /dev/null +++ b/entc/integration/idtype/ent/user_create.go @@ -0,0 +1,189 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "github.com/facebookincubator/ent/dialect/sql" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/user" +) + +// UserCreate is the builder for creating a User entity. +type UserCreate struct { + config + name *string + spouse map[uint64]struct{} + followers map[uint64]struct{} + following map[uint64]struct{} +} + +// SetName sets the name field. +func (uc *UserCreate) SetName(s string) *UserCreate { + uc.name = &s + return uc +} + +// SetSpouseID sets the spouse edge to User by id. +func (uc *UserCreate) SetSpouseID(id uint64) *UserCreate { + if uc.spouse == nil { + uc.spouse = make(map[uint64]struct{}) + } + uc.spouse[id] = struct{}{} + return uc +} + +// SetNillableSpouseID sets the spouse edge to User by id if the given value is not nil. +func (uc *UserCreate) SetNillableSpouseID(id *uint64) *UserCreate { + if id != nil { + uc = uc.SetSpouseID(*id) + } + return uc +} + +// SetSpouse sets the spouse edge to User. +func (uc *UserCreate) SetSpouse(u *User) *UserCreate { + return uc.SetSpouseID(u.ID) +} + +// AddFollowerIDs adds the followers edge to User by ids. +func (uc *UserCreate) AddFollowerIDs(ids ...uint64) *UserCreate { + if uc.followers == nil { + uc.followers = make(map[uint64]struct{}) + } + for i := range ids { + uc.followers[ids[i]] = struct{}{} + } + return uc +} + +// AddFollowers adds the followers edges to User. +func (uc *UserCreate) AddFollowers(u ...*User) *UserCreate { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uc.AddFollowerIDs(ids...) +} + +// AddFollowingIDs adds the following edge to User by ids. +func (uc *UserCreate) AddFollowingIDs(ids ...uint64) *UserCreate { + if uc.following == nil { + uc.following = make(map[uint64]struct{}) + } + for i := range ids { + uc.following[ids[i]] = struct{}{} + } + return uc +} + +// AddFollowing adds the following edges to User. +func (uc *UserCreate) AddFollowing(u ...*User) *UserCreate { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uc.AddFollowingIDs(ids...) +} + +// Save creates the User in the database. +func (uc *UserCreate) Save(ctx context.Context) (*User, error) { + if uc.name == nil { + return nil, errors.New("ent: missing required field \"name\"") + } + if len(uc.spouse) > 1 { + return nil, errors.New("ent: multiple assignments on a unique edge \"spouse\"") + } + return uc.sqlSave(ctx) +} + +// SaveX calls Save and panics if Save returns an error. +func (uc *UserCreate) SaveX(ctx context.Context) *User { + v, err := uc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { + var ( + res sql.Result + u = &User{config: uc.config} + ) + tx, err := uc.driver.Tx(ctx) + if err != nil { + return nil, err + } + builder := sql.Insert(user.Table).Default(uc.driver.Dialect()) + if value := uc.name; value != nil { + builder.Set(user.FieldName, *value) + u.Name = *value + } + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + id, err := res.LastInsertId() + if err != nil { + return nil, rollback(tx, err) + } + u.ID = uint64(id) + if len(uc.spouse) > 0 { + for eid := range uc.spouse { + query, args := sql.Update(user.SpouseTable). + Set(user.SpouseColumn, eid). + Where(sql.EQ(user.FieldID, id)).Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + query, args = sql.Update(user.SpouseTable). + Set(user.SpouseColumn, id). + Where(sql.EQ(user.FieldID, eid).And().IsNull(user.SpouseColumn)).Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + affected, err := res.RowsAffected() + if err != nil { + return nil, rollback(tx, err) + } + if int(affected) < len(uc.spouse) { + return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("\"spouse\" (%v) already connected to a different \"User\"", eid)}) + } + } + } + if len(uc.followers) > 0 { + for eid := range uc.followers { + + query, args := sql.Insert(user.FollowersTable). + Columns(user.FollowersPrimaryKey[1], user.FollowersPrimaryKey[0]). + Values(id, eid). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + } + if len(uc.following) > 0 { + for eid := range uc.following { + + query, args := sql.Insert(user.FollowingTable). + Columns(user.FollowingPrimaryKey[0], user.FollowingPrimaryKey[1]). + Values(id, eid). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + } + if err := tx.Commit(); err != nil { + return nil, err + } + return u, nil +} diff --git a/entc/integration/idtype/ent/user_delete.go b/entc/integration/idtype/ent/user_delete.go new file mode 100644 index 000000000..7541b7625 --- /dev/null +++ b/entc/integration/idtype/ent/user_delete.go @@ -0,0 +1,81 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + + "github.com/facebookincubator/ent/dialect/sql" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/predicate" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/user" +) + +// UserDelete is the builder for deleting a User entity. +type UserDelete struct { + config + predicates []predicate.User +} + +// Where adds a new predicate to the delete builder. +func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { + ud.predicates = append(ud.predicates, ps...) + return ud +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (ud *UserDelete) Exec(ctx context.Context) (int, error) { + return ud.sqlExec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (ud *UserDelete) ExecX(ctx context.Context) int { + n, err := ud.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) { + var res sql.Result + selector := sql.Select().From(sql.Table(user.Table)) + for _, p := range ud.predicates { + p(selector) + } + query, args := sql.Delete(user.Table).FromSelect(selector).Query() + if err := ud.driver.Exec(ctx, query, args, &res); err != nil { + return 0, err + } + affected, err := res.RowsAffected() + if err != nil { + return 0, err + } + return int(affected), nil +} + +// UserDeleteOne is the builder for deleting a single User entity. +type UserDeleteOne struct { + ud *UserDelete +} + +// Exec executes the deletion query. +func (udo *UserDeleteOne) Exec(ctx context.Context) error { + n, err := udo.ud.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &ErrNotFound{user.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (udo *UserDeleteOne) ExecX(ctx context.Context) { + udo.ud.ExecX(ctx) +} diff --git a/entc/integration/idtype/ent/user_query.go b/entc/integration/idtype/ent/user_query.go new file mode 100644 index 000000000..8cd640641 --- /dev/null +++ b/entc/integration/idtype/ent/user_query.go @@ -0,0 +1,645 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "math" + + "github.com/facebookincubator/ent/dialect/sql" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/predicate" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/user" +) + +// UserQuery is the builder for querying User entities. +type UserQuery struct { + config + limit *int + offset *int + order []Order + unique []string + predicates []predicate.User + // intermediate queries. + sql *sql.Selector +} + +// Where adds a new predicate for the builder. +func (uq *UserQuery) Where(ps ...predicate.User) *UserQuery { + uq.predicates = append(uq.predicates, ps...) + return uq +} + +// Limit adds a limit step to the query. +func (uq *UserQuery) Limit(limit int) *UserQuery { + uq.limit = &limit + return uq +} + +// Offset adds an offset step to the query. +func (uq *UserQuery) Offset(offset int) *UserQuery { + uq.offset = &offset + return uq +} + +// Order adds an order step to the query. +func (uq *UserQuery) Order(o ...Order) *UserQuery { + uq.order = append(uq.order, o...) + return uq +} + +// QuerySpouse chains the current query on the spouse edge. +func (uq *UserQuery) QuerySpouse() *UserQuery { + query := &UserQuery{config: uq.config} + t1 := sql.Table(user.Table) + t2 := uq.sqlQuery() + t2.Select(t2.C(user.FieldID)) + query.sql = sql.Select(). + From(t1). + Join(t2). + On(t1.C(user.SpouseColumn), t2.C(user.FieldID)) + return query +} + +// QueryFollowers chains the current query on the followers edge. +func (uq *UserQuery) QueryFollowers() *UserQuery { + query := &UserQuery{config: uq.config} + t1 := sql.Table(user.Table) + t2 := uq.sqlQuery() + t2.Select(t2.C(user.FieldID)) + t3 := sql.Table(user.FollowersTable) + t4 := sql.Select(t3.C(user.FollowersPrimaryKey[0])). + From(t3). + Join(t2). + On(t3.C(user.FollowersPrimaryKey[1]), t2.C(user.FieldID)) + query.sql = sql.Select(). + From(t1). + Join(t4). + On(t1.C(user.FieldID), t4.C(user.FollowersPrimaryKey[0])) + return query +} + +// QueryFollowing chains the current query on the following edge. +func (uq *UserQuery) QueryFollowing() *UserQuery { + query := &UserQuery{config: uq.config} + t1 := sql.Table(user.Table) + t2 := uq.sqlQuery() + t2.Select(t2.C(user.FieldID)) + t3 := sql.Table(user.FollowingTable) + t4 := sql.Select(t3.C(user.FollowingPrimaryKey[1])). + From(t3). + Join(t2). + On(t3.C(user.FollowingPrimaryKey[0]), t2.C(user.FieldID)) + query.sql = sql.Select(). + From(t1). + Join(t4). + On(t1.C(user.FieldID), t4.C(user.FollowingPrimaryKey[1])) + return query +} + +// First returns the first User entity in the query. Returns *ErrNotFound when no user was found. +func (uq *UserQuery) First(ctx context.Context) (*User, error) { + us, err := uq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(us) == 0 { + return nil, &ErrNotFound{user.Label} + } + return us[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (uq *UserQuery) FirstX(ctx context.Context) *User { + u, err := uq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return u +} + +// FirstID returns the first User id in the query. Returns *ErrNotFound when no id was found. +func (uq *UserQuery) FirstID(ctx context.Context) (id uint64, err error) { + var ids []uint64 + if ids, err = uq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &ErrNotFound{user.Label} + return + } + return ids[0], nil +} + +// FirstXID is like FirstID, but panics if an error occurs. +func (uq *UserQuery) FirstXID(ctx context.Context) uint64 { + id, err := uq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns the only User entity in the query, returns an error if not exactly one entity was returned. +func (uq *UserQuery) Only(ctx context.Context) (*User, error) { + us, err := uq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(us) { + case 1: + return us[0], nil + case 0: + return nil, &ErrNotFound{user.Label} + default: + return nil, &ErrNotSingular{user.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (uq *UserQuery) OnlyX(ctx context.Context) *User { + u, err := uq.Only(ctx) + if err != nil { + panic(err) + } + return u +} + +// 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 uint64, err error) { + var ids []uint64 + if ids, err = uq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &ErrNotFound{user.Label} + default: + err = &ErrNotSingular{user.Label} + } + return +} + +// OnlyXID is like OnlyID, but panics if an error occurs. +func (uq *UserQuery) OnlyXID(ctx context.Context) uint64 { + id, err := uq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Users. +func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { + return uq.sqlAll(ctx) +} + +// AllX is like All, but panics if an error occurs. +func (uq *UserQuery) AllX(ctx context.Context) []*User { + us, err := uq.All(ctx) + if err != nil { + panic(err) + } + return us +} + +// IDs executes the query and returns a list of User ids. +func (uq *UserQuery) IDs(ctx context.Context) ([]uint64, error) { + return uq.sqlIDs(ctx) +} + +// IDsX is like IDs, but panics if an error occurs. +func (uq *UserQuery) IDsX(ctx context.Context) []uint64 { + ids, err := uq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (uq *UserQuery) Count(ctx context.Context) (int, error) { + return uq.sqlCount(ctx) +} + +// CountX is like Count, but panics if an error occurs. +func (uq *UserQuery) CountX(ctx context.Context) int { + count, err := uq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (uq *UserQuery) Exist(ctx context.Context) (bool, error) { + return uq.sqlExist(ctx) +} + +// ExistX is like Exist, but panics if an error occurs. +func (uq *UserQuery) ExistX(ctx context.Context) bool { + exist, err := uq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the query builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (uq *UserQuery) Clone() *UserQuery { + return &UserQuery{ + config: uq.config, + limit: uq.limit, + offset: uq.offset, + order: append([]Order{}, uq.order...), + unique: append([]string{}, uq.unique...), + predicates: append([]predicate.User{}, uq.predicates...), + // clone intermediate queries. + sql: uq.sql.Clone(), + } +} + +// GroupBy used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Name string `json:"name,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.User.Query(). +// GroupBy(user.FieldName). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +// +func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { + group := &UserGroupBy{config: uq.config} + group.fields = append([]string{field}, fields...) + group.sql = uq.sqlQuery() + return group +} + +// Select one or more fields from the given query. +// +// Example: +// +// var v []struct { +// Name string `json:"name,omitempty"` +// } +// +// client.User.Query(). +// Select(user.FieldName). +// Scan(ctx, &v) +// +func (uq *UserQuery) Select(field string, fields ...string) *UserSelect { + selector := &UserSelect{config: uq.config} + selector.fields = append([]string{field}, fields...) + selector.sql = uq.sqlQuery() + return selector +} + +func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { + rows := &sql.Rows{} + selector := uq.sqlQuery() + if unique := uq.unique; len(unique) == 0 { + selector.Distinct() + } + query, args := selector.Query() + if err := uq.driver.Query(ctx, query, args, rows); err != nil { + return nil, err + } + defer rows.Close() + var us Users + if err := us.FromRows(rows); err != nil { + return nil, err + } + us.config(uq.config) + return us, nil +} + +func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { + rows := &sql.Rows{} + selector := uq.sqlQuery() + unique := []string{user.FieldID} + if len(uq.unique) > 0 { + unique = uq.unique + } + selector.Count(sql.Distinct(selector.Columns(unique...)...)) + query, args := selector.Query() + if err := uq.driver.Query(ctx, query, args, rows); err != nil { + return 0, err + } + defer rows.Close() + if !rows.Next() { + return 0, errors.New("ent: no rows found") + } + var n int + if err := rows.Scan(&n); err != nil { + return 0, fmt.Errorf("ent: failed reading count: %v", err) + } + return n, nil +} + +func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := uq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("ent: check existence: %v", err) + } + return n > 0, nil +} + +func (uq *UserQuery) sqlIDs(ctx context.Context) ([]uint64, error) { + vs, err := uq.sqlAll(ctx) + if err != nil { + return nil, err + } + var ids []uint64 + for _, v := range vs { + ids = append(ids, v.ID) + } + return ids, nil +} + +func (uq *UserQuery) sqlQuery() *sql.Selector { + t1 := sql.Table(user.Table) + selector := sql.Select(t1.Columns(user.Columns...)...).From(t1) + if uq.sql != nil { + selector = uq.sql + selector.Select(selector.Columns(user.Columns...)...) + } + for _, p := range uq.predicates { + p(selector) + } + for _, p := range uq.order { + p(selector) + } + if offset := uq.offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt64) + } + if limit := uq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// UserGroupBy is the builder for group-by User entities. +type UserGroupBy struct { + config + fields []string + fns []Aggregate + // intermediate queries. + sql *sql.Selector +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (ugb *UserGroupBy) Aggregate(fns ...Aggregate) *UserGroupBy { + ugb.fns = append(ugb.fns, fns...) + return ugb +} + +// Scan applies the group-by query and scan the result into the given value. +func (ugb *UserGroupBy) Scan(ctx context.Context, v interface{}) error { + return ugb.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (ugb *UserGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := ugb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("ent: UserGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (ugb *UserGroupBy) StringsX(ctx context.Context) []string { + v, err := ugb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("ent: UserGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (ugb *UserGroupBy) IntsX(ctx context.Context) []int { + v, err := ugb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("ent: UserGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (ugb *UserGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := ugb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field. +func (ugb *UserGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(ugb.fields) > 1 { + return nil, errors.New("ent: UserGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := ugb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (ugb *UserGroupBy) BoolsX(ctx context.Context) []bool { + v, err := ugb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ugb *UserGroupBy) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := ugb.sqlQuery().Query() + if err := ugb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (ugb *UserGroupBy) sqlQuery() *sql.Selector { + selector := ugb.sql + columns := make([]string, 0, len(ugb.fields)+len(ugb.fns)) + columns = append(columns, ugb.fields...) + for _, fn := range ugb.fns { + columns = append(columns, fn.SQL(selector)) + } + return selector.Select(columns...).GroupBy(ugb.fields...) +} + +// UserSelect is the builder for select fields of User entities. +type UserSelect struct { + config + fields []string + // intermediate queries. + sql *sql.Selector +} + +// Scan applies the selector query and scan the result into the given value. +func (us *UserSelect) Scan(ctx context.Context, v interface{}) error { + return us.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (us *UserSelect) ScanX(ctx context.Context, v interface{}) { + if err := us.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from selector. It is only allowed when selecting one field. +func (us *UserSelect) Strings(ctx context.Context) ([]string, error) { + if len(us.fields) > 1 { + return nil, errors.New("ent: UserSelect.Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := us.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (us *UserSelect) StringsX(ctx context.Context) []string { + v, err := us.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from selector. It is only allowed when selecting one field. +func (us *UserSelect) Ints(ctx context.Context) ([]int, error) { + if len(us.fields) > 1 { + return nil, errors.New("ent: UserSelect.Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := us.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (us *UserSelect) IntsX(ctx context.Context) []int { + v, err := us.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from selector. It is only allowed when selecting one field. +func (us *UserSelect) Float64s(ctx context.Context) ([]float64, error) { + if len(us.fields) > 1 { + return nil, errors.New("ent: UserSelect.Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := us.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (us *UserSelect) Float64sX(ctx context.Context) []float64 { + v, err := us.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from selector. It is only allowed when selecting one field. +func (us *UserSelect) Bools(ctx context.Context) ([]bool, error) { + if len(us.fields) > 1 { + return nil, errors.New("ent: UserSelect.Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := us.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (us *UserSelect) BoolsX(ctx context.Context) []bool { + v, err := us.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +func (us *UserSelect) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := us.sqlQuery().Query() + if err := us.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (us *UserSelect) sqlQuery() sql.Querier { + view := "user_view" + return sql.Select(us.fields...).From(us.sql.As(view)) +} diff --git a/entc/integration/idtype/ent/user_update.go b/entc/integration/idtype/ent/user_update.go new file mode 100644 index 000000000..51daf9ab6 --- /dev/null +++ b/entc/integration/idtype/ent/user_update.go @@ -0,0 +1,647 @@ +// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +// Code generated (@generated) by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "github.com/facebookincubator/ent/dialect/sql" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/predicate" + "github.com/facebookincubator/ent/entc/integration/idtype/ent/user" +) + +// UserUpdate is the builder for updating User entities. +type UserUpdate struct { + config + name *string + spouse map[uint64]struct{} + followers map[uint64]struct{} + following map[uint64]struct{} + clearedSpouse bool + removedFollowers map[uint64]struct{} + removedFollowing map[uint64]struct{} + predicates []predicate.User +} + +// Where adds a new predicate for the builder. +func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate { + uu.predicates = append(uu.predicates, ps...) + return uu +} + +// SetName sets the name field. +func (uu *UserUpdate) SetName(s string) *UserUpdate { + uu.name = &s + return uu +} + +// SetSpouseID sets the spouse edge to User by id. +func (uu *UserUpdate) SetSpouseID(id uint64) *UserUpdate { + if uu.spouse == nil { + uu.spouse = make(map[uint64]struct{}) + } + uu.spouse[id] = struct{}{} + return uu +} + +// SetNillableSpouseID sets the spouse edge to User by id if the given value is not nil. +func (uu *UserUpdate) SetNillableSpouseID(id *uint64) *UserUpdate { + if id != nil { + uu = uu.SetSpouseID(*id) + } + return uu +} + +// SetSpouse sets the spouse edge to User. +func (uu *UserUpdate) SetSpouse(u *User) *UserUpdate { + return uu.SetSpouseID(u.ID) +} + +// AddFollowerIDs adds the followers edge to User by ids. +func (uu *UserUpdate) AddFollowerIDs(ids ...uint64) *UserUpdate { + if uu.followers == nil { + uu.followers = make(map[uint64]struct{}) + } + for i := range ids { + uu.followers[ids[i]] = struct{}{} + } + return uu +} + +// AddFollowers adds the followers edges to User. +func (uu *UserUpdate) AddFollowers(u ...*User) *UserUpdate { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uu.AddFollowerIDs(ids...) +} + +// AddFollowingIDs adds the following edge to User by ids. +func (uu *UserUpdate) AddFollowingIDs(ids ...uint64) *UserUpdate { + if uu.following == nil { + uu.following = make(map[uint64]struct{}) + } + for i := range ids { + uu.following[ids[i]] = struct{}{} + } + return uu +} + +// AddFollowing adds the following edges to User. +func (uu *UserUpdate) AddFollowing(u ...*User) *UserUpdate { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uu.AddFollowingIDs(ids...) +} + +// ClearSpouse clears the spouse edge to User. +func (uu *UserUpdate) ClearSpouse() *UserUpdate { + uu.clearedSpouse = true + return uu +} + +// RemoveFollowerIDs removes the followers edge to User by ids. +func (uu *UserUpdate) RemoveFollowerIDs(ids ...uint64) *UserUpdate { + if uu.removedFollowers == nil { + uu.removedFollowers = make(map[uint64]struct{}) + } + for i := range ids { + uu.removedFollowers[ids[i]] = struct{}{} + } + return uu +} + +// RemoveFollowers removes followers edges to User. +func (uu *UserUpdate) RemoveFollowers(u ...*User) *UserUpdate { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uu.RemoveFollowerIDs(ids...) +} + +// RemoveFollowingIDs removes the following edge to User by ids. +func (uu *UserUpdate) RemoveFollowingIDs(ids ...uint64) *UserUpdate { + if uu.removedFollowing == nil { + uu.removedFollowing = make(map[uint64]struct{}) + } + for i := range ids { + uu.removedFollowing[ids[i]] = struct{}{} + } + return uu +} + +// RemoveFollowing removes following edges to User. +func (uu *UserUpdate) RemoveFollowing(u ...*User) *UserUpdate { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uu.RemoveFollowingIDs(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.spouse) > 1 { + return 0, errors.New("ent: multiple assignments on a unique edge \"spouse\"") + } + return uu.sqlSave(ctx) +} + +// SaveX is like Save, but panics if an error occurs. +func (uu *UserUpdate) SaveX(ctx context.Context) int { + affected, err := uu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (uu *UserUpdate) Exec(ctx context.Context) error { + _, err := uu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (uu *UserUpdate) ExecX(ctx context.Context) { + if err := uu.Exec(ctx); err != nil { + panic(err) + } +} + +func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { + selector := sql.Select(user.FieldID).From(sql.Table(user.Table)) + for _, p := range uu.predicates { + p(selector) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err = uu.driver.Query(ctx, query, args, rows); err != nil { + return 0, err + } + defer rows.Close() + var ids []int + for rows.Next() { + var id int + if err := rows.Scan(&id); err != nil { + return 0, fmt.Errorf("ent: failed reading id: %v", err) + } + ids = append(ids, id) + } + if len(ids) == 0 { + return 0, nil + } + + tx, err := uu.driver.Tx(ctx) + if err != nil { + return 0, err + } + var ( + res sql.Result + builder = sql.Update(user.Table).Where(sql.InInts(user.FieldID, ids...)) + ) + if value := uu.name; value != nil { + builder.Set(user.FieldName, *value) + } + if !builder.Empty() { + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if uu.clearedSpouse { + query, args := sql.Update(user.SpouseTable). + SetNull(user.SpouseColumn). + Where(sql.InInts(user.FieldID, ids...)). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + query, args = sql.Update(user.SpouseTable). + SetNull(user.SpouseColumn). + Where(sql.InInts(user.SpouseColumn, ids...)). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if len(uu.spouse) > 0 { + if n := len(ids); n > 1 { + return 0, rollback(tx, fmt.Errorf("ent: can't link O2O edge \"spouse\" to %d vertices (> 1)", n)) + } + for eid := range uu.spouse { + eid := int(eid) + query, args := sql.Update(user.SpouseTable). + Set(user.SpouseColumn, eid). + Where(sql.EQ(user.FieldID, ids[0])).Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + query, args = sql.Update(user.SpouseTable). + Set(user.SpouseColumn, ids[0]). + Where(sql.EQ(user.FieldID, eid).And().IsNull(user.SpouseColumn)).Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + affected, err := res.RowsAffected() + if err != nil { + return 0, rollback(tx, err) + } + if int(affected) < len(uu.spouse) { + return 0, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("\"spouse\" (%v) already connected to a different \"User\"", eid)}) + } + } + } + if len(uu.removedFollowers) > 0 { + eids := make([]int, len(uu.removedFollowers)) + for eid := range uu.removedFollowers { + eid := int(eid) + eids = append(eids, eid) + } + query, args := sql.Delete(user.FollowersTable). + Where(sql.InInts(user.FollowersPrimaryKey[1], ids...)). + Where(sql.InInts(user.FollowersPrimaryKey[0], eids...)). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if len(uu.followers) > 0 { + values := make([][]int, 0, len(ids)) + for _, id := range ids { + for eid := range uu.followers { + eid := int(eid) + values = append(values, []int{id, eid}) + } + } + builder := sql.Insert(user.FollowersTable). + Columns(user.FollowersPrimaryKey[1], user.FollowersPrimaryKey[0]) + for _, v := range values { + builder.Values(v[0], v[1]) + } + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if len(uu.removedFollowing) > 0 { + eids := make([]int, len(uu.removedFollowing)) + for eid := range uu.removedFollowing { + eid := int(eid) + eids = append(eids, eid) + } + query, args := sql.Delete(user.FollowingTable). + Where(sql.InInts(user.FollowingPrimaryKey[0], ids...)). + Where(sql.InInts(user.FollowingPrimaryKey[1], eids...)). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if len(uu.following) > 0 { + values := make([][]int, 0, len(ids)) + for _, id := range ids { + for eid := range uu.following { + eid := int(eid) + values = append(values, []int{id, eid}) + } + } + builder := sql.Insert(user.FollowingTable). + Columns(user.FollowingPrimaryKey[0], user.FollowingPrimaryKey[1]) + for _, v := range values { + builder.Values(v[0], v[1]) + } + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return 0, rollback(tx, err) + } + } + if err = tx.Commit(); err != nil { + return 0, err + } + return len(ids), nil +} + +// UserUpdateOne is the builder for updating a single User entity. +type UserUpdateOne struct { + config + id uint64 + name *string + spouse map[uint64]struct{} + followers map[uint64]struct{} + following map[uint64]struct{} + clearedSpouse bool + removedFollowers map[uint64]struct{} + removedFollowing map[uint64]struct{} +} + +// SetName sets the name field. +func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { + uuo.name = &s + return uuo +} + +// SetSpouseID sets the spouse edge to User by id. +func (uuo *UserUpdateOne) SetSpouseID(id uint64) *UserUpdateOne { + if uuo.spouse == nil { + uuo.spouse = make(map[uint64]struct{}) + } + uuo.spouse[id] = struct{}{} + return uuo +} + +// SetNillableSpouseID sets the spouse edge to User by id if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableSpouseID(id *uint64) *UserUpdateOne { + if id != nil { + uuo = uuo.SetSpouseID(*id) + } + return uuo +} + +// SetSpouse sets the spouse edge to User. +func (uuo *UserUpdateOne) SetSpouse(u *User) *UserUpdateOne { + return uuo.SetSpouseID(u.ID) +} + +// AddFollowerIDs adds the followers edge to User by ids. +func (uuo *UserUpdateOne) AddFollowerIDs(ids ...uint64) *UserUpdateOne { + if uuo.followers == nil { + uuo.followers = make(map[uint64]struct{}) + } + for i := range ids { + uuo.followers[ids[i]] = struct{}{} + } + return uuo +} + +// AddFollowers adds the followers edges to User. +func (uuo *UserUpdateOne) AddFollowers(u ...*User) *UserUpdateOne { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uuo.AddFollowerIDs(ids...) +} + +// AddFollowingIDs adds the following edge to User by ids. +func (uuo *UserUpdateOne) AddFollowingIDs(ids ...uint64) *UserUpdateOne { + if uuo.following == nil { + uuo.following = make(map[uint64]struct{}) + } + for i := range ids { + uuo.following[ids[i]] = struct{}{} + } + return uuo +} + +// AddFollowing adds the following edges to User. +func (uuo *UserUpdateOne) AddFollowing(u ...*User) *UserUpdateOne { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uuo.AddFollowingIDs(ids...) +} + +// ClearSpouse clears the spouse edge to User. +func (uuo *UserUpdateOne) ClearSpouse() *UserUpdateOne { + uuo.clearedSpouse = true + return uuo +} + +// RemoveFollowerIDs removes the followers edge to User by ids. +func (uuo *UserUpdateOne) RemoveFollowerIDs(ids ...uint64) *UserUpdateOne { + if uuo.removedFollowers == nil { + uuo.removedFollowers = make(map[uint64]struct{}) + } + for i := range ids { + uuo.removedFollowers[ids[i]] = struct{}{} + } + return uuo +} + +// RemoveFollowers removes followers edges to User. +func (uuo *UserUpdateOne) RemoveFollowers(u ...*User) *UserUpdateOne { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uuo.RemoveFollowerIDs(ids...) +} + +// RemoveFollowingIDs removes the following edge to User by ids. +func (uuo *UserUpdateOne) RemoveFollowingIDs(ids ...uint64) *UserUpdateOne { + if uuo.removedFollowing == nil { + uuo.removedFollowing = make(map[uint64]struct{}) + } + for i := range ids { + uuo.removedFollowing[ids[i]] = struct{}{} + } + return uuo +} + +// RemoveFollowing removes following edges to User. +func (uuo *UserUpdateOne) RemoveFollowing(u ...*User) *UserUpdateOne { + ids := make([]uint64, len(u)) + for i := range u { + ids[i] = u[i].ID + } + return uuo.RemoveFollowingIDs(ids...) +} + +// Save executes the query and returns the updated entity. +func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { + if len(uuo.spouse) > 1 { + return nil, errors.New("ent: multiple assignments on a unique edge \"spouse\"") + } + return uuo.sqlSave(ctx) +} + +// SaveX is like Save, but panics if an error occurs. +func (uuo *UserUpdateOne) SaveX(ctx context.Context) *User { + u, err := uuo.Save(ctx) + if err != nil { + panic(err) + } + return u +} + +// Exec executes the query on the entity. +func (uuo *UserUpdateOne) Exec(ctx context.Context) error { + _, err := uuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (uuo *UserUpdateOne) ExecX(ctx context.Context) { + if err := uuo.Exec(ctx); err != nil { + panic(err) + } +} + +func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) { + selector := sql.Select(user.Columns...).From(sql.Table(user.Table)) + user.ID(uuo.id)(selector) + rows := &sql.Rows{} + query, args := selector.Query() + if err = uuo.driver.Query(ctx, query, args, rows); err != nil { + return nil, err + } + defer rows.Close() + var ids []int + for rows.Next() { + var id int + u = &User{config: uuo.config} + if err := u.FromRows(rows); err != nil { + return nil, fmt.Errorf("ent: failed scanning row into User: %v", err) + } + id = int(u.ID) + ids = append(ids, id) + } + switch n := len(ids); { + case n == 0: + return nil, fmt.Errorf("ent: User not found with id: %v", uuo.id) + case n > 1: + return nil, fmt.Errorf("ent: more than one User with the same id: %v", uuo.id) + } + + tx, err := uuo.driver.Tx(ctx) + if err != nil { + return nil, err + } + var ( + res sql.Result + builder = sql.Update(user.Table).Where(sql.InInts(user.FieldID, ids...)) + ) + if value := uuo.name; value != nil { + builder.Set(user.FieldName, *value) + u.Name = *value + } + if !builder.Empty() { + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if uuo.clearedSpouse { + query, args := sql.Update(user.SpouseTable). + SetNull(user.SpouseColumn). + Where(sql.InInts(user.FieldID, ids...)). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + query, args = sql.Update(user.SpouseTable). + SetNull(user.SpouseColumn). + Where(sql.InInts(user.SpouseColumn, ids...)). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if len(uuo.spouse) > 0 { + if n := len(ids); n > 1 { + return nil, rollback(tx, fmt.Errorf("ent: can't link O2O edge \"spouse\" to %d vertices (> 1)", n)) + } + for eid := range uuo.spouse { + eid := int(eid) + query, args := sql.Update(user.SpouseTable). + Set(user.SpouseColumn, eid). + Where(sql.EQ(user.FieldID, ids[0])).Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + query, args = sql.Update(user.SpouseTable). + Set(user.SpouseColumn, ids[0]). + Where(sql.EQ(user.FieldID, eid).And().IsNull(user.SpouseColumn)).Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + affected, err := res.RowsAffected() + if err != nil { + return nil, rollback(tx, err) + } + if int(affected) < len(uuo.spouse) { + return nil, rollback(tx, &ErrConstraintFailed{msg: fmt.Sprintf("\"spouse\" (%v) already connected to a different \"User\"", eid)}) + } + } + } + if len(uuo.removedFollowers) > 0 { + eids := make([]int, len(uuo.removedFollowers)) + for eid := range uuo.removedFollowers { + eid := int(eid) + eids = append(eids, eid) + } + query, args := sql.Delete(user.FollowersTable). + Where(sql.InInts(user.FollowersPrimaryKey[1], ids...)). + Where(sql.InInts(user.FollowersPrimaryKey[0], eids...)). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if len(uuo.followers) > 0 { + values := make([][]int, 0, len(ids)) + for _, id := range ids { + for eid := range uuo.followers { + eid := int(eid) + values = append(values, []int{id, eid}) + } + } + builder := sql.Insert(user.FollowersTable). + Columns(user.FollowersPrimaryKey[1], user.FollowersPrimaryKey[0]) + for _, v := range values { + builder.Values(v[0], v[1]) + } + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if len(uuo.removedFollowing) > 0 { + eids := make([]int, len(uuo.removedFollowing)) + for eid := range uuo.removedFollowing { + eid := int(eid) + eids = append(eids, eid) + } + query, args := sql.Delete(user.FollowingTable). + Where(sql.InInts(user.FollowingPrimaryKey[0], ids...)). + Where(sql.InInts(user.FollowingPrimaryKey[1], eids...)). + Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if len(uuo.following) > 0 { + values := make([][]int, 0, len(ids)) + for _, id := range ids { + for eid := range uuo.following { + eid := int(eid) + values = append(values, []int{id, eid}) + } + } + builder := sql.Insert(user.FollowingTable). + Columns(user.FollowingPrimaryKey[0], user.FollowingPrimaryKey[1]) + for _, v := range values { + builder.Values(v[0], v[1]) + } + query, args := builder.Query() + if err := tx.Exec(ctx, query, args, &res); err != nil { + return nil, rollback(tx, err) + } + } + if err = tx.Commit(); err != nil { + return nil, err + } + return u, nil +} diff --git a/entc/integration/idtype/idtype_test.go b/entc/integration/idtype/idtype_test.go new file mode 100644 index 000000000..07f60fc63 --- /dev/null +++ b/entc/integration/idtype/idtype_test.go @@ -0,0 +1,32 @@ +// Copyright 2019-present Facebook Inc. All rights reserved. +// This source code is licensed under the Apache 2.0 license found +// in the LICENSE file in the root directory of this source tree. + +package template + +import ( + "context" + "testing" + + "github.com/facebookincubator/ent/dialect/sql" + "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" +) + +func TestIDType(t *testing.T) { + drv, err := sql.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") + require.NoError(t, err) + defer drv.Close() + ctx := context.Background() + client := ent.NewClient(ent.Driver(drv)) + require.NoError(t, client.Schema.Create(ctx, migrate.WithGlobalUniqueID(true))) + + a8m := client.User.Create().SetName("a8m").SaveX(ctx) + require.Equal(t, "a8m", a8m.Name) + neta := client.User.Create().SetName("neta").SetSpouse(a8m).SaveX(ctx) + require.Equal(t, "neta", neta.Name) + require.Equal(t, []string{a8m.Name}, neta.QuerySpouse().Select(user.FieldName).StringsX(ctx)) +}