diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index ad1f00654..2cfb94d12 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -581,7 +581,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\xb8\x12\x7d\x96\x7e\xc5\xdc\xc0\x2d\xa4\xc0\x61\xd2\xbc\xdd\xf4\xe6\x02\xd9\x7c\x00\xde\x6d\x92\x36\x4e\x77\x1f\xda\x62\x41\x4b\x43\x9b\x1b\x9a\x74\x48\xca\x4d\x60\xe8\xbf\x2f\x48\x4a\xb6\xec\x38\xb1\xe3\x16\xcd\xee\x62\x1f\x82\x58\xe2\x70\xe6\xcc\xe1\xe1\x0c\xa9\xc9\x64\x77\x3b\x3e\x56\xa3\x7b\xcd\xfb\x03\x0b\xfb\x7b\x6f\xfe\xbb\x33\xd2\x68\x50\x5a\x38\xa3\x19\xf6\x94\xba\x81\x8e\xcc\x08\x1c\x09\x01\xde\xc8\x80\x1b\xd7\x63\xcc\x49\x7c\x3d\xe0\x06\x8c\x2a\x74\x86\x90\xa9\x1c\x81\x1b\x10\x3c\x43\x69\x30\x87\x42\xe6\xa8\xc1\x0e\x10\x8e\x46\x34\x1b\x20\xec\x93\xbd\x7a\x14\x98\x2a\x64\x1e\x73\xe9\xc7\xdf\x75\x8e\x4f\x2f\xba\xa7\xc0\xb8\x40\xa8\xde\x69\xa5\x2c\xe4\x5c\x63\x66\x95\xbe\x07\xc5\xc0\x36\x82\x59\x8d\x48\xe2\xed\xdd\xb2\x8c\xe3\xc9\x04\x72\x64\x5c\x22\x6c\xe5\x9c\x0a\xcc\xec\xae\xb9\x15\xbb\x99\x46\x6a\x71\x0b\xca\xd2\x59\xb4\x7a\x05\x17\x0e\xcf\xc1\x21\x8c\xa8\xc9\xa8\x80\x16\xe9\x66\x6a\x84\xe4\xa7\x6a\xa4\x32\xd4\x98\x21\x1f\x07\xcb\xe9\xef\xe9\x74\x17\x90\x15\x32\x83\x64\xce\xb6\x2c\x61\xbb\x19\xa5\x2c\x53\x30\xb7\xa2\x4b\xc7\x98\x64\xf6\x0e\x32\x25\x2d\xde\x59\x72\x1c\xfe\xa7\x90\x78\x73\x72\x41\x87\x08\x65\xd9\x06\xd4\x5a\xe9\x14\x26\x71\x34\xa6\x1a\x92\x38\x8a\x26\x13\xf8\xca\xed\x00\x5a\xe4\x34\xef\xa3\x81\xb2\xd4\x68\x9c\x53\x72\x85\xa6\x10\x76\x32\x01\x94\xb9\x03\x14\x45\x75\xd8\x43\x3f\x7e\x12\x58\x58\x44\x48\x72\xed\x7e\x4d\x87\xd3\x34\x44\x69\x91\xab\x46\x1a\x87\xf0\xba\x89\x6c\x92\x29\xc9\x78\xff\x00\x16\x9d\x85\xf7\x65\x1c\xa5\x71\x64\xef\x7c\x02\x8e\xb1\x47\x62\x5e\xdf\x39\x1a\xd2\x38\xe2\xcc\x5b\xfe\xe7\x10\x24\x17\x2e\xdd\x48\xa3\x2d\xb4\x74\x8f\xde\x49\x1c\x95\x71\xc4\xa5\x41\x6d\x9d\xbf\x2a\x33\xd2\xf1\x6f\x7c\x4a\xe4\x3d\xcd\x6e\x68\xdf\xa1\x23\xd7\xb4\x27\x30\x25\x27\xc8\x68\x21\x6c\x92\xc6\xd1\x64\xb2\x03\x9a\xca\x3e\x42\xeb\xf7\x36\xb4\x98\x73\xd2\x22\x67\x1c\x45\x6e\x02\x59\x9c\xc1\x98\x8a\x02\x97\xc1\x75\xb3\x5b\xac\x96\x84\x9f\x05\x65\xf9\xb6\x9a\xd0\x40\xed\xe3\x70\xe6\x8c\x3b\xe6\xe7\xee\xe5\x45\xf0\xed\x96\x82\x4d\xc9\xf8\xc3\x28\x49\xce\xa9\x36\x03\x2a\x92\x6d\xef\x23\xf5\x46\x0f\x59\x88\x96\x10\x11\x45\x51\xf0\x19\xe8\x20\x5d\x7c\x48\x80\x7b\x66\x4e\x56\xc6\x52\x69\xbd\x94\x7a\x05\x4b\x6b\x84\x28\x0c\x56\xc8\x9e\xe7\xa4\x81\xd6\xfb\xa9\x95\xf6\x40\x30\xd5\xe4\xae\xd5\x45\x66\x6b\xc2\xc0\x33\xcb\x19\x48\x65\xdd\xe8\x05\x17\xc2\xad\x14\x94\xe5\xf6\x54\xb7\x3e\x42\xec\x73\x6c\x86\xe0\xf9\x94\xbf\x00\xf9\x1d\x35\xb6\x73\xe2\xf4\xd3\x06\xf7\x57\x25\x72\xe5\xe9\xe2\xb2\xbf\x34\x1d\xd2\x39\x69\x26\x94\xae\x94\x9e\x56\x42\xf4\x68\x76\x93\x54\x62\x4e\xe3\x00\x6c\x21\xdb\xce\xc9\x34\x37\x1f\xa3\x63\xba\x56\x73\xd9\x87\xb2\x34\x56\x67\x4a\x8e\xc9\x99\xd2\x43\x6a\x3b\xd2\x26\x2e\x95\x37\x7b\xa9\xcb\x38\xac\x43\x8d\xec\xfa\x7e\xe4\x1e\x13\x9e\xa7\x8d\x6d\xbc\x20\x5d\x0c\xd2\xad\x77\x7f\x50\xae\x40\xf9\x60\x5f\xbb\x67\x5c\xd4\x6c\x0a\xff\x87\xbd\x39\xa9\x52\x99\x3b\xbb\x8f\x92\xdf\x16\xe8\x7e\x75\x51\xb0\x2b\x64\x1e\xd7\xee\x36\x5c\xee\x5f\x86\x8a\x63\x50\x30\xd0\xc8\x50\xa3\xcc\x10\x7c\x95\x75\x32\x64\x4a\x03\xf2\xdc\x17\x46\x0f\x73\x2d\x20\xb5\xbc\x1d\x0a\x8b\xc3\x91\xa0\x76\x69\xa5\xde\x75\xe4\xa1\xb6\x3c\xdf\x72\xb9\xef\x54\x41\xa3\xdb\x02\xf5\x7d\x1b\xa8\xee\x9b\x66\x41\xf8\x38\xca\xa9\xc5\xa5\x6b\x8f\xa1\x2c\x34\x97\x9f\x04\x5f\x51\xf4\x98\xfc\x91\x1c\x2b\x51\x0c\xe5\xdc\x26\x40\x9e\xcf\x66\xfe\x36\x40\x8d\x89\xab\xaf\xa7\x1f\xd6\x91\x5c\x1b\x78\x9e\xa6\xe4\x83\x83\x9f\x84\x6d\x5f\x4b\xf0\xe0\x10\xec\x1d\x39\xbd\xc3\x2c\xa8\xba\x91\x62\x1b\x5e\x6b\x34\xe9\xdb\x25\xf5\x61\x95\x5c\x67\xf5\x62\x8e\xb3\x1f\x4b\xd9\x93\x8c\xa1\x17\xfe\x92\xd8\xee\xed\x22\x7b\x9e\xfc\x23\x99\x27\x29\xe9\x98\x8b\x42\x88\x75\x41\xbc\x14\xe9\x94\x31\xcc\x2c\xce\xca\x97\x46\x43\xae\xd4\x57\x73\x54\x0d\x2c\x00\xda\x38\x10\x67\xc0\xa5\x4d\xea\x78\x29\xfc\xef\x39\x65\x61\x65\xbc\xd7\xa7\x5a\x7b\x3a\x35\xe5\xd2\x9e\x51\x2e\x30\x9f\x0c\x4d\xff\x00\xd8\xd0\x92\xee\x48\x73\x69\x59\xb2\xf5\x79\x2b\x04\xa8\x0e\x0a\x9f\xb7\x20\x79\x35\x4e\x81\x0a\x8d\x34\xbf\x77\x27\x1e\xe9\xe1\x81\x55\x40\x21\xe7\xcc\xd7\x13\x0b\x61\xde\x6c\xda\x56\x58\xea\x72\x2e\xc7\x72\xae\x81\xb9\x62\x8b\xe4\x7c\xff\x1c\xe0\x45\x4b\x91\x73\x4a\x5d\xcc\xbd\xaa\x96\xf7\xdc\xc3\x1b\xff\xb0\x53\xa1\xec\x98\x8e\x9b\x3b\x2d\xf7\x14\x6a\x0b\x67\x3e\x9d\x3a\x6b\xa8\x8f\x56\xb8\x47\x8e\x3c\xab\xb6\x6b\xd8\x0f\xe6\x91\x79\xef\x7f\x69\x4c\xfa\x14\x00\x96\xe5\x97\x36\xac\x6b\xde\x73\xe6\xb3\x68\xbf\xba\x26\x6e\x7c\xa7\x9b\xab\x96\x33\x42\x16\xba\x8c\x6b\x2e\x3b\x1a\x19\x04\xaa\x8d\x3f\xec\xa3\xef\x71\x5c\x42\x4f\xd9\x01\x7c\xa5\xf7\x86\xcc\xda\x4e\x23\x0c\xba\x38\x8b\x61\x9a\x54\x46\xd1\x4b\x6c\xfd\xe5\x6a\xbd\x7c\x59\xb1\x7e\xd7\xbe\xb9\x71\xdb\xdc\xb0\x6b\xc6\x7f\xad\xc5\xbc\xdc\x3f\xaf\x17\x73\xe4\x00\xb8\x7c\xde\x57\xb8\x5e\x66\x75\x47\xe4\x52\x27\xe9\xc6\x8d\xb5\x71\xb9\xf8\x9e\x3a\xd9\xf0\xa8\x30\x13\x89\xeb\xf7\xa3\xb6\xe7\xf7\xb9\x4d\xbf\x76\xd6\xd4\xcc\x37\x49\x66\xb5\x62\x02\x81\xeb\xf6\xfd\x95\x97\xbe\xa7\x82\x7c\x97\x9e\xff\xad\x2d\x5f\x49\x04\xc5\xe0\x61\xe7\x7f\x35\xde\xa8\xef\xdf\xe0\xbd\x59\x33\x85\xfa\x7c\x50\x2e\xdc\x6c\xa7\x37\x97\x69\xbb\xa8\x3b\xcf\x54\xfc\x8d\x2b\x5a\xa0\x01\x1b\x57\xcc\xfa\xd2\x76\x64\x15\x4f\x9e\x81\xe7\xd3\xde\x97\xb5\x4f\x73\xf5\x65\x3e\x9a\x01\x6c\xdc\xcb\x3d\x1e\x07\xe5\x79\xd1\xe3\x25\xed\x6f\xf9\x29\xe4\x6f\xdf\x0e\x36\xbd\x05\x2c\x69\x22\x0f\xb8\x7f\x39\x5a\x9e\x62\xe5\x87\x5d\x94\x1e\xa3\x68\xa6\xa9\x7f\x4b\xe8\x3f\xb7\x84\xd6\xab\xbc\xf8\x05\xae\xb9\xe4\xc7\x6a\x38\xe4\x36\x79\xb8\xbc\xcb\xbe\xdb\x56\xef\x16\xbf\x9a\xb5\x9d\x55\x1c\x3e\xd5\x57\x41\x9e\xfe\x6a\xdf\x3c\xf5\xd4\x5f\xc6\x9e\xa8\xe9\x8f\x16\xf4\xea\xa8\xb3\x44\x36\xab\x44\x33\x4f\xc9\x0c\xf7\x9f\x01\x00\x00\xff\xff\x61\x5a\xe6\x6e\x31\x19\x00\x00") +var _templateDialectSqlCreateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x59\x5b\x6f\xdb\xb8\x12\x7e\x96\x7e\xc5\x9c\xc0\x2d\xa4\xc0\x61\xd2\xbc\x9d\xf4\xe4\x00\xd9\x5c\x00\xef\x36\x49\x1b\xa7\xbb\x0f\x6d\xb1\xa0\xa5\xa1\xcd\x0d\x4d\x29\x24\xe5\x26\x08\xf4\xdf\x17\x43\x5d\x2c\x3b\xce\xb5\x45\xb3\xbb\xd8\x87\x20\x12\xc9\xe1\x7c\xf3\xf1\xe3\x0c\x29\xdf\xdc\x6c\xae\x87\xfb\x59\x7e\x6d\xe4\x78\xe2\x60\x7b\xeb\xcd\x7f\x37\x72\x83\x16\xb5\x83\x23\x9e\xe0\x28\xcb\x2e\x60\xa0\x13\x06\x7b\x4a\x81\x1f\x64\x81\xfa\xcd\x0c\x53\x16\x9e\x4f\xa4\x05\x9b\x15\x26\x41\x48\xb2\x14\x41\x5a\x50\x32\x41\x6d\x31\x85\x42\xa7\x68\xc0\x4d\x10\xf6\x72\x9e\x4c\x10\xb6\xd9\x56\xd3\x0b\x22\x2b\x74\x1a\x4a\xed\xfb\xdf\x0d\xf6\x0f\x4f\x86\x87\x20\xa4\x42\xa8\xdb\x4c\x96\x39\x48\xa5\xc1\xc4\x65\xe6\x1a\x32\x01\xae\xe3\xcc\x19\x44\x16\xae\x6f\x96\x65\x18\xde\xdc\x40\x8a\x42\x6a\x84\xb5\x54\x72\x85\x89\xdb\xb4\x97\x6a\x33\x31\xc8\x1d\xae\x41\x59\xd2\x88\xde\xa8\x90\x8a\xf0\xec\xec\x42\xce\x6d\xc2\x15\xf4\xd8\x30\xc9\x72\x64\x3f\xd5\x3d\xf5\x40\x83\x09\xca\x59\x35\xb2\x7d\x6e\xcd\xeb\x41\x42\xa2\x4a\x2d\x0d\xe9\xb1\xa3\xea\xb9\xea\x91\x02\x7a\x6c\x70\xc0\x3e\x5a\x34\x07\x1e\x55\x4a\x3d\x41\xc7\x68\x17\x78\x9e\xa3\x4e\xdb\x06\x32\xa8\xcd\xa9\x99\x62\x12\x85\x4e\x20\x5a\x80\x53\x96\xb0\xde\x0d\xa4\x2c\x63\xb0\x97\x6a\xc8\x67\x18\x25\xee\x0a\x92\x4c\x3b\xbc\x72\x6c\xbf\xfa\x1f\x43\xe4\x87\xb3\x13\x3e\x45\x28\xcb\x3e\xa0\x31\x99\x89\xe1\x26\x0c\x66\xdc\x40\x14\x06\x04\xea\xab\x74\x13\xe8\xb1\xc3\x74\x8c\x14\x82\x41\x4b\x93\xb2\x33\xb4\x85\x72\x73\x40\x41\xd0\xb8\xdd\xf5\xfd\x07\x15\xd1\xcb\x08\x59\x6a\xe8\xa9\xed\x8e\xe3\xca\x4b\x8f\x9d\x75\xc2\xd8\x85\xd7\x5d\x64\x37\x49\xa6\x85\x1c\xef\xc0\xf2\x64\x55\x7b\x19\x06\x71\x18\xb8\x2b\x1f\x00\x31\x7e\x87\xcf\xf3\x2b\xa2\x21\x0e\x03\x29\xfc\xc8\xff\xec\x82\x96\x8a\xc2\x0d\x0c\xba\xc2\x68\x7a\xf5\x93\x84\x41\x19\x06\x52\x5b\x34\x8e\xe6\xab\x23\x63\x03\xdf\xe2\x43\x62\xef\x79\x72\xc1\xc7\x84\x8e\x9d\xf3\x91\xc2\x98\x1d\xa0\xe0\x85\x72\x51\x4c\x6b\xb9\x01\x86\xeb\x31\x42\xef\xf7\x3e\xf4\x84\x97\x81\x68\x55\x10\x10\x82\x19\x57\x05\xae\x42\x4b\xc6\x3d\xd1\x88\xce\x6b\x07\xca\xf2\x6d\x6d\xd0\x01\xed\xdd\x90\x9c\x04\x1b\xd8\x9f\x87\xa7\x27\xd5\xdc\xb4\x12\xa2\xe5\xe2\x0f\x9b\x69\x76\xcc\x8d\x9d\x70\x15\xad\xfb\x39\x62\x3f\xe8\x36\x09\xc1\x0a\x1e\x82\x20\xa8\xe6\xac\xd8\x60\x43\xbc\x1d\xbf\x57\x2e\xa9\xca\x3a\xae\x9d\x57\xd2\xa8\x10\x71\x83\x10\x95\xc5\x1a\xd9\xd3\x26\xe9\xa0\xf5\xf3\x34\x42\xbb\xa5\x97\xda\x78\xe8\x4c\x91\xb8\x86\x30\xf0\xcc\x4a\x01\x3a\x73\xd4\x7b\x22\x95\xa2\x85\x82\xb2\x5c\x6f\x65\xeb\x3d\x84\x3e\xc6\xae\x0b\x99\xb6\xfc\x55\x90\xdf\x71\xeb\x06\x07\x24\x9f\x3e\xd0\x5f\x1d\xc8\x99\xa7\x4b\xea\xf1\xca\x70\x68\x97\x77\x02\x8a\x1f\x54\x9e\xc9\x94\x1a\xf1\xe4\x22\xaa\xb5\x1c\x87\x41\x9d\x18\x16\xa2\x1d\x1c\xb4\xb1\x71\x4a\x12\xe4\x67\x60\x87\xce\x48\x3d\x86\xc8\x87\xbb\x94\x60\x62\x28\x4b\xeb\x4c\x92\xe9\x19\x3b\xca\xcc\x94\xbb\x81\x76\x11\x45\xf9\x66\x2b\x26\x32\xaa\x25\x6a\x40\x9f\x5f\xe7\xf4\x1a\xc9\x34\xee\x6c\xf0\x25\x51\x63\x95\xdb\x9a\xbc\x50\x89\x5a\xa1\xbe\xb5\xe3\xe9\x1d\x97\xe5\x1c\xc3\xff\x61\x6b\x41\xc5\x3e\x14\x64\x1f\xb5\xbc\x2c\x90\x9e\x86\xa8\xc4\x19\x0a\x8f\x6b\x73\x1d\x4e\xb7\x4f\xab\x5c\x64\x51\x09\x30\x28\xd0\xa0\x4e\x10\x7c\x8a\x27\x85\x8a\xcc\x00\xca\xd4\x67\x65\x0f\xf3\x51\x40\x1a\xe5\x13\x0a\x87\xd3\x5c\x71\xb7\xb2\x4c\x6c\x12\x79\x68\x9c\x4c\xd7\x28\xf6\x8d\xda\x69\x70\x59\xa0\xb9\xee\x03\x37\x63\xdb\x4d\x15\x1f\xf3\x94\x3b\x5c\x29\x0b\xac\x12\x46\x57\x19\xac\x9a\x2b\x08\xee\xda\x19\xc8\xf6\x33\x55\x4c\xf5\xc2\xfe\x40\x99\xce\x2d\x7f\x9b\xa0\xc1\x88\x32\xef\xe1\x87\xc7\xa8\xb1\x0f\x32\x8d\x63\xf6\x81\xe0\x47\x55\x46\x68\xd4\xb9\xb3\x0b\xee\x8a\x1d\x5e\x61\x52\x09\xbe\x13\x62\x1f\x5e\x1b\xb4\xf1\xdb\x15\xa9\xe3\x21\x25\xcf\x53\xc9\x02\x67\x3f\x96\xb2\x7b\x19\x43\x2f\xfc\x15\xbe\xa9\x75\x99\x3d\x4f\xfe\x9e\x4e\xa3\x98\x0d\xec\x49\xa1\xd4\x63\x41\xbc\x14\xe9\x5c\x08\x4c\x1c\xce\x33\x9b\x41\xcb\xce\xb2\xaf\x76\xaf\xee\x58\x02\xf4\x6c\x47\x52\x80\xd4\x2e\x6a\xfc\xc5\xf0\xbf\xa7\xa4\x85\x07\xfd\xbd\x3e\x34\xc6\xd3\x69\xb8\xd4\xee\x88\x4b\x85\xe9\xcd\xd4\x8e\x77\x40\x4c\x1d\x1b\xe6\x46\x6a\x27\xa2\xb5\xcf\x6b\x95\x83\xfa\x08\xf1\x79\x0d\xa2\x57\xb3\x18\xb8\x32\xc8\xd3\x6b\x3a\x0b\x69\x0f\x0f\x5c\x06\x1c\x52\x29\x7c\x3e\x71\x50\xd9\xcd\xcd\xd6\xaa\xa5\x2e\x17\x62\x2c\x17\x6a\x1b\x95\x60\x64\xc7\xdb\xc7\x00\x2f\x9a\x8a\x68\x52\x4e\x3e\xb7\xea\x5c\x3e\xa2\x97\x37\xfe\x65\xa3\x46\x39\xb0\x03\xb2\x6d\xd3\x3d\x87\x66\x04\x0d\x6f\x4d\xe7\xb5\xf6\xce\x0c\x77\xc7\x61\xe8\xa1\xed\x5a\xed\x07\x7b\x87\xdd\xfb\x5f\x3a\x46\x9f\x2a\x80\x65\xf9\xa5\x0f\x8f\x1d\x3e\xa2\xe1\x73\x6f\xbf\x52\x7d\xb7\xbe\xd2\x2d\x64\xcb\x39\x21\x4b\x55\x86\x8a\xcb\x86\x41\x01\x15\xd5\xd6\xdf\x34\xd0\xd7\x38\xa9\x61\x94\xb9\x09\x7c\xe5\xd7\x96\xcd\xcb\x4e\xc7\x0d\x92\x9f\x65\x37\x5d\x2a\x83\xe0\x25\xb6\xfe\x6a\xb5\x9e\xbe\xac\x58\xbf\x6b\xdd\x7c\x76\xd9\x7c\x66\xd5\x0c\xff\x5a\x8b\x79\xba\x7d\xdc\x2c\x66\x4e\x00\x28\x9e\xf7\x35\xae\x97\x59\xdd\x9c\x9d\x9a\x28\x7e\x76\x61\xed\xdc\x3b\xbe\xa7\x4e\x9e\x79\x54\x98\x8b\x84\xea\x7d\xde\xf7\xfc\x3e\xb5\xe8\x37\x93\x75\x35\xf3\x4d\x92\x79\x58\x31\x15\x81\x8f\xad\xfb\x0f\xde\x07\xef\x73\xf2\x5d\x6a\xfe\xb7\x96\xfc\x4c\x23\x64\x02\x6e\x57\xfe\x57\xb3\x67\xd5\xfd\x0b\xbc\xb6\x8f\x0c\xa1\x39\x1f\x94\x4b\x97\xde\xf6\xe6\xd2\x96\x8b\xa6\xf2\xb4\xe2\x6f\x6f\x6e\xcd\xde\xc1\xce\xed\xb3\xb9\xb4\xed\xb9\x4c\x46\x4f\xc0\xf3\x69\xeb\xcb\xa3\x4f\x73\xcd\x3d\x3f\x98\x03\xec\x5c\xd9\x3d\x1e\x82\xf2\x34\xef\xe1\x8a\xf2\xb7\xfa\x14\xf2\xb7\x2f\x07\xcf\xbd\x05\xac\x28\x22\xb7\xb8\x7f\x39\x5a\xee\x63\xe5\x87\x5d\x94\xee\xa2\x68\xae\xa9\x7f\x53\xe8\x3f\x37\x85\x36\xab\xbc\xfc\x71\xae\xbb\xe4\xfb\xd9\x74\x2a\x5d\x74\x7b\x79\x57\x7d\xd1\xad\xdb\x96\x3f\xa8\xf5\x69\x54\x58\xfd\x4e\xd0\x7c\x5e\xbf\xf7\x27\x83\xee\xa9\xa7\xf9\x32\x76\x4f\x4e\xbf\x33\xa1\xd7\x47\x9d\x15\xb2\x79\x48\x34\x8b\x94\xcc\x71\xff\x19\x00\x00\xff\xff\x7e\x9a\x9c\x39\xae\x19\x00\x00") func templateDialectSqlCreateTmplBytes() ([]byte, error) { return bindataRead( @@ -596,7 +596,7 @@ func templateDialectSqlCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6449, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/dialect/sql/create.tmpl", size: 6574, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/dialect/sql/create.tmpl b/entc/gen/template/dialect/sql/create.tmpl index 28f80ab48..4ff59ee3e 100644 --- a/entc/gen/template/dialect/sql/create.tmpl +++ b/entc/gen/template/dialect/sql/create.tmpl @@ -7,6 +7,10 @@ in the LICENSE file in the root directory of this source tree. {{ define "dialect/sql/create" }} {{ $builder := pascal $.Scope.Builder }} {{ $receiver := receiver $builder }} +{{ $fields := $.Fields }} +{{ if $.ID.UserDefined }} + {{ $fields = append $fields $.ID }} +{{ end }} func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name }}, error) { var ( @@ -19,7 +23,7 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name return nil, err } insert := builder.Insert({{ $.Package }}.Table).Default() - {{- range $_, $f := $.Fields }} + {{- range $_, $f := $fields }} if value := {{ $receiver }}.{{- $f.BuilderField }}; value != nil { {{- if $f.IsJSON }} buf, err := json.Marshal(*value) @@ -37,7 +41,7 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name if err != nil { return nil, rollback(tx, err) } - {{ $.Receiver }}.ID = {{ if $.ID.IsString }}strconv.FormatInt(id, 10){{ else }}{{ $.ID.Type }}(id){{ end }} + {{ $.Receiver }}.ID = {{ if and $.ID.IsString (not $.ID.UserDefined) }}strconv.FormatInt(id, 10){{ else }}{{ $.ID.Type }}(id){{ end }} {{- range $_, $e := $.Edges }} if len({{ $receiver }}.{{ $e.BuilderField }}) > 0 { {{- if and $e.Unique $e.SelfRef }}{{/* O2O with self reference */}} diff --git a/entc/integration/customid/customid_test.go b/entc/integration/customid/customid_test.go new file mode 100644 index 000000000..524f7b96b --- /dev/null +++ b/entc/integration/customid/customid_test.go @@ -0,0 +1,34 @@ +// 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 customid + +import ( + "context" + "testing" + + "github.com/facebookincubator/ent/entc/integration/customid/ent" + + _ "github.com/mattn/go-sqlite3" + "github.com/stretchr/testify/require" +) + +func TestCustomID(t *testing.T) { + client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") + require.NoError(t, err) + defer client.Close() + ctx := context.Background() + require.NoError(t, client.Schema.Create(ctx)) + + nat := client.User.Create().SaveX(ctx) + require.Equal(t, 1, nat.ID) + _, err = client.User.Create().SetID(1).Save(ctx) + require.True(t, ent.IsConstraintFailure(err), "duplicate id") + a8m := client.User.Create().SetID(5).SaveX(ctx) + require.Equal(t, 5, a8m.ID) + + hub := client.Group.Create().SetID(3).AddUsers(a8m, nat).SaveX(ctx) + require.Equal(t, 3, hub.ID) + require.Equal(t, []int{1, 5}, hub.QueryUsers().IDsX(ctx)) +} diff --git a/entc/integration/customid/ent/client.go b/entc/integration/customid/ent/client.go index 000cb2bc8..a6971218e 100644 --- a/entc/integration/customid/ent/client.go +++ b/entc/integration/customid/ent/client.go @@ -124,7 +124,7 @@ func (c *GroupClient) UpdateOne(gr *Group) *GroupUpdateOne { } // UpdateOneID returns an update builder for the given id. -func (c *GroupClient) UpdateOneID(id string) *GroupUpdateOne { +func (c *GroupClient) UpdateOneID(id int) *GroupUpdateOne { return &GroupUpdateOne{config: c.config, id: id} } @@ -139,7 +139,7 @@ func (c *GroupClient) DeleteOne(gr *Group) *GroupDeleteOne { } // DeleteOneID returns a delete builder for the given id. -func (c *GroupClient) DeleteOneID(id string) *GroupDeleteOne { +func (c *GroupClient) DeleteOneID(id int) *GroupDeleteOne { return &GroupDeleteOne{c.Delete().Where(group.ID(id))} } @@ -149,12 +149,12 @@ func (c *GroupClient) Query() *GroupQuery { } // Get returns a Group entity by its id. -func (c *GroupClient) Get(ctx context.Context, id string) (*Group, error) { +func (c *GroupClient) Get(ctx context.Context, id int) (*Group, error) { return c.Query().Where(group.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. -func (c *GroupClient) GetX(ctx context.Context, id string) *Group { +func (c *GroupClient) GetX(ctx context.Context, id int) *Group { gr, err := c.Get(ctx, id) if err != nil { panic(err) @@ -165,7 +165,7 @@ func (c *GroupClient) GetX(ctx context.Context, id string) *Group { // QueryUsers queries the users edge of a Group. func (c *GroupClient) QueryUsers(gr *Group) *UserQuery { query := &UserQuery{config: c.config} - id := gr.id() + id := gr.ID step := &sql.Step{} step.From.V = id step.From.Table = group.Table diff --git a/entc/integration/customid/ent/ent.go b/entc/integration/customid/ent/ent.go index 1a80c1610..a0562c1ea 100644 --- a/entc/integration/customid/ent/ent.go +++ b/entc/integration/customid/ent/ent.go @@ -226,8 +226,8 @@ func insertLastID(ctx context.Context, tx dialect.Tx, insert *sql.InsertBuilder) } // keys returns the keys/ids from the edge map. -func keys(m map[string]struct{}) []string { - s := make([]string, 0, len(m)) +func keys(m map[int]struct{}) []int { + s := make([]int, 0, len(m)) for id := range m { s = append(s, id) } diff --git a/entc/integration/customid/ent/group.go b/entc/integration/customid/ent/group.go index 932e722bd..e7acc50d3 100644 --- a/entc/integration/customid/ent/group.go +++ b/entc/integration/customid/ent/group.go @@ -4,7 +4,6 @@ package ent import ( "fmt" - "strconv" "strings" "github.com/facebookincubator/ent/dialect/sql" @@ -14,7 +13,7 @@ import ( type Group struct { config // ID of the ent. - ID string `json:"id,omitempty"` + ID int `json:"id,omitempty"` } // FromRows scans the sql response data into Group. @@ -28,7 +27,7 @@ func (gr *Group) FromRows(rows *sql.Rows) error { ); err != nil { return err } - gr.ID = strconv.Itoa(scangr.ID) + gr.ID = scangr.ID return nil } @@ -64,12 +63,6 @@ func (gr *Group) String() string { return builder.String() } -// id returns the int representation of the ID field. -func (gr *Group) id() int { - id, _ := strconv.Atoi(gr.ID) - return id -} - // Groups is a parsable slice of Group. type Groups []*Group diff --git a/entc/integration/customid/ent/group/where.go b/entc/integration/customid/ent/group/where.go index 8710fd7d2..aae9c5928 100644 --- a/entc/integration/customid/ent/group/where.go +++ b/entc/integration/customid/ent/group/where.go @@ -3,44 +3,39 @@ package group import ( - "strconv" - "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/customid/ent/predicate" ) // ID filters vertices based on their identifier. -func ID(id string) predicate.Group { +func ID(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id string) predicate.Group { +func IDEQ(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.EQ(s.C(FieldID), id)) }, ) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id string) predicate.Group { +func IDNEQ(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.NEQ(s.C(FieldID), id)) }, ) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...string) predicate.Group { +func IDIn(ids ...int) predicate.Group { return predicate.Group( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -51,7 +46,7 @@ func IDIn(ids ...string) predicate.Group { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.In(s.C(FieldID), v...)) }, @@ -59,7 +54,7 @@ func IDIn(ids ...string) predicate.Group { } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...string) predicate.Group { +func IDNotIn(ids ...int) predicate.Group { return predicate.Group( func(s *sql.Selector) { // if not arguments were provided, append the FALSE constants, @@ -70,7 +65,7 @@ func IDNotIn(ids ...string) predicate.Group { } v := make([]interface{}, len(ids)) for i := range v { - v[i], _ = strconv.Atoi(ids[i]) + v[i] = ids[i] } s.Where(sql.NotIn(s.C(FieldID), v...)) }, @@ -78,40 +73,36 @@ func IDNotIn(ids ...string) predicate.Group { } // IDGT applies the GT predicate on the ID field. -func IDGT(id string) predicate.Group { +func IDGT(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.GT(s.C(FieldID), id)) }, ) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id string) predicate.Group { +func IDGTE(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.GTE(s.C(FieldID), id)) }, ) } // IDLT applies the LT predicate on the ID field. -func IDLT(id string) predicate.Group { +func IDLT(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.LT(s.C(FieldID), id)) }, ) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id string) predicate.Group { +func IDLTE(id int) predicate.Group { return predicate.Group( func(s *sql.Selector) { - id, _ := strconv.Atoi(id) s.Where(sql.LTE(s.C(FieldID), id)) }, ) diff --git a/entc/integration/customid/ent/group_create.go b/entc/integration/customid/ent/group_create.go index 902388c56..ff04c96ef 100644 --- a/entc/integration/customid/ent/group_create.go +++ b/entc/integration/customid/ent/group_create.go @@ -4,7 +4,6 @@ package ent import ( "context" - "strconv" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/customid/ent/group" @@ -13,13 +12,13 @@ import ( // GroupCreate is the builder for creating a Group entity. type GroupCreate struct { config - id *string + id *int users map[int]struct{} } // SetID sets the id field. -func (gc *GroupCreate) SetID(s string) *GroupCreate { - gc.id = &s +func (gc *GroupCreate) SetID(i int) *GroupCreate { + gc.id = &i return gc } @@ -68,11 +67,15 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) { return nil, err } insert := builder.Insert(group.Table).Default() + if value := gc.id; value != nil { + insert.Set(group.FieldID, *value) + gr.ID = *value + } id, err := insertLastID(ctx, tx, insert.Returning(group.FieldID)) if err != nil { return nil, rollback(tx, err) } - gr.ID = strconv.FormatInt(id, 10) + gr.ID = int(id) if len(gc.users) > 0 { for eid := range gc.users { diff --git a/entc/integration/customid/ent/group_query.go b/entc/integration/customid/ent/group_query.go index 80c0f9eff..a27731560 100644 --- a/entc/integration/customid/ent/group_query.go +++ b/entc/integration/customid/ent/group_query.go @@ -92,8 +92,8 @@ func (gq *GroupQuery) FirstX(ctx context.Context) *Group { } // FirstID returns the first Group id in the query. Returns *ErrNotFound when no id was found. -func (gq *GroupQuery) FirstID(ctx context.Context) (id string, err error) { - var ids []string +func (gq *GroupQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = gq.Limit(1).IDs(ctx); err != nil { return } @@ -105,7 +105,7 @@ func (gq *GroupQuery) FirstID(ctx context.Context) (id string, err error) { } // FirstXID is like FirstID, but panics if an error occurs. -func (gq *GroupQuery) FirstXID(ctx context.Context) string { +func (gq *GroupQuery) FirstXID(ctx context.Context) int { id, err := gq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -139,8 +139,8 @@ func (gq *GroupQuery) OnlyX(ctx context.Context) *Group { } // OnlyID returns the only Group id in the query, returns an error if not exactly one id was returned. -func (gq *GroupQuery) OnlyID(ctx context.Context) (id string, err error) { - var ids []string +func (gq *GroupQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int if ids, err = gq.Limit(2).IDs(ctx); err != nil { return } @@ -156,7 +156,7 @@ func (gq *GroupQuery) OnlyID(ctx context.Context) (id string, err error) { } // OnlyXID is like OnlyID, but panics if an error occurs. -func (gq *GroupQuery) OnlyXID(ctx context.Context) string { +func (gq *GroupQuery) OnlyXID(ctx context.Context) int { id, err := gq.OnlyID(ctx) if err != nil { panic(err) @@ -179,8 +179,8 @@ func (gq *GroupQuery) AllX(ctx context.Context) []*Group { } // IDs executes the query and returns a list of Group ids. -func (gq *GroupQuery) IDs(ctx context.Context) ([]string, error) { - var ids []string +func (gq *GroupQuery) IDs(ctx context.Context) ([]int, error) { + var ids []int if err := gq.Select(group.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -188,7 +188,7 @@ func (gq *GroupQuery) IDs(ctx context.Context) ([]string, error) { } // IDsX is like IDs, but panics if an error occurs. -func (gq *GroupQuery) IDsX(ctx context.Context) []string { +func (gq *GroupQuery) IDsX(ctx context.Context) []int { ids, err := gq.IDs(ctx) if err != nil { panic(err) diff --git a/entc/integration/customid/ent/group_update.go b/entc/integration/customid/ent/group_update.go index 7441937a5..6ffe4b910 100644 --- a/entc/integration/customid/ent/group_update.go +++ b/entc/integration/customid/ent/group_update.go @@ -162,7 +162,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { // GroupUpdateOne is the builder for updating a single Group entity. type GroupUpdateOne struct { config - id string + id int users map[int]struct{} removedUsers map[int]struct{} } @@ -253,7 +253,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (gr *Group, err error) { if err := gr.FromRows(rows); err != nil { return nil, fmt.Errorf("ent: failed scanning row into Group: %v", err) } - id = gr.id() + id = gr.ID ids = append(ids, id) } switch n := len(ids); { diff --git a/entc/integration/customid/ent/migrate/schema.go b/entc/integration/customid/ent/migrate/schema.go index 300e5060b..78846dbc8 100644 --- a/entc/integration/customid/ent/migrate/schema.go +++ b/entc/integration/customid/ent/migrate/schema.go @@ -32,7 +32,7 @@ var ( } // GroupUsersColumns holds the columns for the "group_users" table. GroupUsersColumns = []*schema.Column{ - {Name: "group_id", Type: field.TypeString}, + {Name: "group_id", Type: field.TypeInt}, {Name: "user_id", Type: field.TypeInt}, } // GroupUsersTable holds the schema information for the "group_users" table. diff --git a/entc/integration/customid/ent/schema/group.go b/entc/integration/customid/ent/schema/group.go index 61d64ef17..902291bf8 100644 --- a/entc/integration/customid/ent/schema/group.go +++ b/entc/integration/customid/ent/schema/group.go @@ -1,3 +1,7 @@ +// 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 ( @@ -14,7 +18,7 @@ type Group struct { // Fields of the Group. func (Group) Fields() []ent.Field { return []ent.Field{ - field.String("id"), + field.Int("id"), } } diff --git a/entc/integration/customid/ent/schema/user.go b/entc/integration/customid/ent/schema/user.go index d71c4853c..2e8cb9693 100644 --- a/entc/integration/customid/ent/schema/user.go +++ b/entc/integration/customid/ent/schema/user.go @@ -1,3 +1,7 @@ +// 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 ( diff --git a/entc/integration/customid/ent/user_create.go b/entc/integration/customid/ent/user_create.go index 83c640de1..18c53efc0 100644 --- a/entc/integration/customid/ent/user_create.go +++ b/entc/integration/customid/ent/user_create.go @@ -4,7 +4,6 @@ package ent import ( "context" - "strconv" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/customid/ent/user" @@ -14,7 +13,7 @@ import ( type UserCreate struct { config id *int - groups map[string]struct{} + groups map[int]struct{} } // SetID sets the id field. @@ -24,9 +23,9 @@ func (uc *UserCreate) SetID(i int) *UserCreate { } // AddGroupIDs adds the groups edge to Group by ids. -func (uc *UserCreate) AddGroupIDs(ids ...string) *UserCreate { +func (uc *UserCreate) AddGroupIDs(ids ...int) *UserCreate { if uc.groups == nil { - uc.groups = make(map[string]struct{}) + uc.groups = make(map[int]struct{}) } for i := range ids { uc.groups[ids[i]] = struct{}{} @@ -36,7 +35,7 @@ func (uc *UserCreate) AddGroupIDs(ids ...string) *UserCreate { // AddGroups adds the groups edges to Group. func (uc *UserCreate) AddGroups(g ...*Group) *UserCreate { - ids := make([]string, len(g)) + ids := make([]int, len(g)) for i := range g { ids[i] = g[i].ID } @@ -68,6 +67,10 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { return nil, err } insert := builder.Insert(user.Table).Default() + if value := uc.id; value != nil { + insert.Set(user.FieldID, *value) + u.ID = *value + } id, err := insertLastID(ctx, tx, insert.Returning(user.FieldID)) if err != nil { return nil, rollback(tx, err) @@ -75,10 +78,6 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { u.ID = int(id) if len(uc.groups) > 0 { for eid := range uc.groups { - eid, err := strconv.Atoi(eid) - if err != nil { - return nil, rollback(tx, err) - } query, args := builder.Insert(user.GroupsTable). Columns(user.GroupsPrimaryKey[1], user.GroupsPrimaryKey[0]). diff --git a/entc/integration/customid/ent/user_update.go b/entc/integration/customid/ent/user_update.go index 295e87c5f..0720935f4 100644 --- a/entc/integration/customid/ent/user_update.go +++ b/entc/integration/customid/ent/user_update.go @@ -5,7 +5,6 @@ package ent import ( "context" "fmt" - "strconv" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/customid/ent/predicate" @@ -15,8 +14,8 @@ import ( // UserUpdate is the builder for updating User entities. type UserUpdate struct { config - groups map[string]struct{} - removedGroups map[string]struct{} + groups map[int]struct{} + removedGroups map[int]struct{} predicates []predicate.User } @@ -27,9 +26,9 @@ func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate { } // AddGroupIDs adds the groups edge to Group by ids. -func (uu *UserUpdate) AddGroupIDs(ids ...string) *UserUpdate { +func (uu *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate { if uu.groups == nil { - uu.groups = make(map[string]struct{}) + uu.groups = make(map[int]struct{}) } for i := range ids { uu.groups[ids[i]] = struct{}{} @@ -39,7 +38,7 @@ func (uu *UserUpdate) AddGroupIDs(ids ...string) *UserUpdate { // AddGroups adds the groups edges to Group. func (uu *UserUpdate) AddGroups(g ...*Group) *UserUpdate { - ids := make([]string, len(g)) + ids := make([]int, len(g)) for i := range g { ids[i] = g[i].ID } @@ -47,9 +46,9 @@ func (uu *UserUpdate) AddGroups(g ...*Group) *UserUpdate { } // RemoveGroupIDs removes the groups edge to Group by ids. -func (uu *UserUpdate) RemoveGroupIDs(ids ...string) *UserUpdate { +func (uu *UserUpdate) RemoveGroupIDs(ids ...int) *UserUpdate { if uu.removedGroups == nil { - uu.removedGroups = make(map[string]struct{}) + uu.removedGroups = make(map[int]struct{}) } for i := range ids { uu.removedGroups[ids[i]] = struct{}{} @@ -59,7 +58,7 @@ func (uu *UserUpdate) RemoveGroupIDs(ids ...string) *UserUpdate { // RemoveGroups removes groups edges to Group. func (uu *UserUpdate) RemoveGroups(g ...*Group) *UserUpdate { - ids := make([]string, len(g)) + ids := make([]int, len(g)) for i := range g { ids[i] = g[i].ID } @@ -127,11 +126,6 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { if len(uu.removedGroups) > 0 { eids := make([]int, len(uu.removedGroups)) for eid := range uu.removedGroups { - eid, serr := strconv.Atoi(eid) - if serr != nil { - err = rollback(tx, serr) - return - } eids = append(eids, eid) } query, args := builder.Delete(user.GroupsTable). @@ -146,11 +140,6 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { values := make([][]int, 0, len(ids)) for _, id := range ids { for eid := range uu.groups { - eid, serr := strconv.Atoi(eid) - if serr != nil { - err = rollback(tx, serr) - return - } values = append(values, []int{id, eid}) } } @@ -174,14 +163,14 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { type UserUpdateOne struct { config id int - groups map[string]struct{} - removedGroups map[string]struct{} + groups map[int]struct{} + removedGroups map[int]struct{} } // AddGroupIDs adds the groups edge to Group by ids. -func (uuo *UserUpdateOne) AddGroupIDs(ids ...string) *UserUpdateOne { +func (uuo *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne { if uuo.groups == nil { - uuo.groups = make(map[string]struct{}) + uuo.groups = make(map[int]struct{}) } for i := range ids { uuo.groups[ids[i]] = struct{}{} @@ -191,7 +180,7 @@ func (uuo *UserUpdateOne) AddGroupIDs(ids ...string) *UserUpdateOne { // AddGroups adds the groups edges to Group. func (uuo *UserUpdateOne) AddGroups(g ...*Group) *UserUpdateOne { - ids := make([]string, len(g)) + ids := make([]int, len(g)) for i := range g { ids[i] = g[i].ID } @@ -199,9 +188,9 @@ func (uuo *UserUpdateOne) AddGroups(g ...*Group) *UserUpdateOne { } // RemoveGroupIDs removes the groups edge to Group by ids. -func (uuo *UserUpdateOne) RemoveGroupIDs(ids ...string) *UserUpdateOne { +func (uuo *UserUpdateOne) RemoveGroupIDs(ids ...int) *UserUpdateOne { if uuo.removedGroups == nil { - uuo.removedGroups = make(map[string]struct{}) + uuo.removedGroups = make(map[int]struct{}) } for i := range ids { uuo.removedGroups[ids[i]] = struct{}{} @@ -211,7 +200,7 @@ func (uuo *UserUpdateOne) RemoveGroupIDs(ids ...string) *UserUpdateOne { // RemoveGroups removes groups edges to Group. func (uuo *UserUpdateOne) RemoveGroups(g ...*Group) *UserUpdateOne { - ids := make([]string, len(g)) + ids := make([]int, len(g)) for i := range g { ids[i] = g[i].ID } @@ -282,11 +271,6 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) { if len(uuo.removedGroups) > 0 { eids := make([]int, len(uuo.removedGroups)) for eid := range uuo.removedGroups { - eid, serr := strconv.Atoi(eid) - if serr != nil { - err = rollback(tx, serr) - return - } eids = append(eids, eid) } query, args := builder.Delete(user.GroupsTable). @@ -301,11 +285,6 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) { values := make([][]int, 0, len(ids)) for _, id := range ids { for eid := range uuo.groups { - eid, serr := strconv.Atoi(eid) - if serr != nil { - err = rollback(tx, serr) - return - } values = append(values, []int{id, eid}) } } diff --git a/entc/integration/idtype/idtype_test.go b/entc/integration/idtype/idtype_test.go index 5e8b3c06c..5de0cfc92 100644 --- a/entc/integration/idtype/idtype_test.go +++ b/entc/integration/idtype/idtype_test.go @@ -2,7 +2,7 @@ // 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 +package idtype import ( "context"