diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index 1a6095aad..ad68efe2f 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -601,7 +601,7 @@ func templateDialectSqlCreateTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlDecodeTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x57\x5f\x6f\xdb\x38\x12\x7f\xb6\x3f\xc5\x54\x70\x02\xc9\x70\xe8\xb4\x38\x1c\x70\x09\x72\x40\x51\x37\x80\x0e\x87\x6c\x11\x37\x7d\x29\x8a\x2d\x23\x8d\x62\x6e\x28\xd2\x21\x69\x27\x81\x56\xdf\x7d\x41\x52\xb2\x29\xff\x49\xdc\x2e\xba\x6f\xa2\x86\x1c\xce\xfc\x66\xe6\x37\xc3\xaa\x1a\x0f\xfb\x1f\xe4\xfc\x59\xb1\xbb\x99\x81\x77\xa7\x6f\xff\x73\x32\x57\xa8\x51\x18\xb8\xa4\x19\xde\x4a\x79\x0f\xa9\xc8\x08\xbc\xe7\x1c\xdc\x26\x0d\x56\xae\x96\x98\x93\xfe\xe7\x19\xd3\xa0\xe5\x42\x65\x08\x99\xcc\x11\x98\x06\xce\x32\x14\x1a\x73\x58\x88\x1c\x15\x98\x19\xc2\xfb\x39\xcd\x66\x08\xef\xc8\x69\x2b\x85\x42\x2e\x44\xde\x67\xc2\xc9\xff\x9f\x7e\xf8\x78\x35\xfd\x08\x05\xe3\x08\xcd\x3f\x25\xa5\x81\x9c\x29\xcc\x8c\x54\xcf\x20\x0b\x30\xc1\x65\x46\x21\x92\xfe\x70\x5c\xd7\xfd\x7e\x55\x41\x8e\x05\x13\x08\x51\xce\x28\xc7\xcc\x8c\xf5\x03\x1f\xe7\x68\x2d\x1a\x4b\x81\x11\xd4\xb5\xdd\x35\x50\x98\x21\x5b\xa2\x82\xb3\x0b\x18\x90\xeb\x76\x65\x95\x8c\xc7\x70\xa9\x64\x79\x2d\x1f\x35\xe8\x8c\x0a\xed\x8c\xd0\x0f\xdc\x7a\x3b\x97\xd6\xe4\x9c\x1a\x0a\x4c\x18\x09\x56\x17\xb9\xa2\x25\x42\x5d\x93\x7e\xb1\x10\x19\xc4\x1d\xfd\x75\x0d\xc3\x70\x53\xb2\x52\x1e\x2b\x7b\xc3\x50\x3f\x70\x62\x97\x09\xa0\x52\x52\x41\xd5\xef\x55\xd5\x09\x0c\xec\xd5\xd6\xba\xb9\x62\xc2\x40\x64\x97\x51\x47\x6f\xbf\xb7\xa4\xca\x19\xe0\xb6\xd6\x35\x68\xa3\x16\x99\xb1\x1a\x7a\xe9\x04\xc0\xca\x58\x01\x03\x92\x4e\x48\xaa\xa7\x46\x31\x71\x07\x75\xcd\x84\xa9\x2a\x40\xae\xad\x39\xce\xb4\x74\x42\x3e\x3f\xcf\x9b\x25\x8a\xdc\x29\xef\x55\x15\x28\x2a\xee\x10\x06\xbf\x8f\x60\x50\x78\xa4\x2e\x19\xf2\x5c\xfb\x0d\xde\xce\x82\x4c\xdd\xb5\x4e\x62\xad\xb0\x2a\x0b\x72\xb5\xe0\xbc\x51\xea\x75\xb5\x7a\xeb\x7e\x6f\x3c\x76\x90\x4a\x65\xb3\x62\x86\x0a\x41\xcf\xe4\x82\xe7\x70\x8b\x1e\x6b\x0b\x15\xd5\x6d\xfc\xbf\x3b\x23\x3f\xd1\xec\x9e\xde\x39\x9c\x3f\x48\xbe\x28\x85\xfe\x4e\xfa\x3d\x56\x58\xd8\xac\x6d\x16\x4d\x32\xcd\xa8\x88\xad\x69\xc7\x01\x2e\x24\x9d\x8c\x5a\x73\x5f\xf1\xa8\x7b\xce\x7b\xd2\x75\x6f\xa5\xa9\xf5\x27\x39\x77\x16\xbc\xb9\x00\xc1\xb8\xc3\x5e\xa1\x59\x28\x61\xff\x3a\x6f\x37\xd2\x81\xa4\x13\xb8\xd8\x13\x1a\x6d\x54\x26\xc5\x92\xa4\x46\xd2\xb8\xeb\x41\xd2\x8d\xd9\x5a\x10\x40\xfb\xba\x83\x76\x87\xbd\xb7\x20\xa9\xfe\xdf\xf4\xb7\xab\xc6\x6d\x56\xc0\x92\xf2\x05\xda\x03\xaf\x01\x70\x0e\x1c\x45\xec\xb6\x27\xf0\x5f\x38\x75\x2e\xf7\x82\x40\xfc\xa1\xa5\x20\x37\xa2\xa4\x4a\xcf\x28\xf7\x3b\x47\x70\xbc\x09\xc3\x2e\xdd\xdb\x58\xf6\x56\x70\x16\xa5\x21\x1f\x6d\x85\x14\x71\xb4\x68\xb5\x43\xe1\x4e\x36\x29\xe7\x2b\xec\x0c\x8e\x96\xd1\xc8\x2a\x4a\x9c\x02\xe7\x61\xeb\xbc\x83\xd0\x23\x70\xc5\x38\xa7\xb7\x1c\xd7\x18\xbc\xe6\x3a\xf9\x42\x39\xcb\x1b\xbb\x0e\xf1\x07\x2e\x40\xe0\x63\xec\x45\x4d\x35\x78\xa3\x86\x07\x1e\xaf\x2a\x4f\x00\x05\x44\x47\x9a\x1c\xe9\xa8\xb1\x70\x63\xef\x9f\x61\xc9\xb5\xc7\xb7\xfc\x6e\xab\xf6\x9f\xb8\x39\x2c\x91\xf0\xbb\x89\xa6\x60\xbc\xef\xb9\xd6\x2a\xfd\x62\x73\xc4\x76\x13\x2b\xf3\x7c\x6b\x9e\xe7\xa8\xa1\x90\xca\x6d\x10\xb6\x3e\x96\x7e\x57\xa1\x64\x09\x2d\x6b\xb6\x9c\xbb\xc1\xb1\x6b\xa5\x71\x02\x5f\xbf\x31\x61\x50\x15\x34\xc3\xaa\xb6\xd1\x6b\x6c\xd8\xfa\xef\xaa\x9f\x15\x20\xa4\xf1\xa5\x79\xa3\x51\x4d\x5c\x43\xb1\xc6\xdb\x3b\xad\xa7\xa9\x30\xff\xfe\xd7\x36\x85\x06\x8c\xb7\xaa\xc9\xca\xf1\xc5\x01\xc4\x73\xbc\xc5\x9a\xeb\xa3\x6b\xe6\xf4\x88\x51\xad\xd9\x5d\x8b\x99\x5f\x78\xcc\x1a\x80\xcc\x8c\x1a\x78\xb4\xb4\xea\x1d\xc5\xbc\x8b\x19\xc4\xb4\x30\xb8\x06\x36\xb1\x4a\x8d\x74\x2a\x42\x18\x7d\x71\xe9\x03\xdb\x5a\x68\x55\xdc\x58\x42\x08\x09\x20\x0e\x3a\x9c\xad\xb6\x72\x04\xae\xc1\xad\xe8\x44\x27\x23\xb7\xd8\x43\xf7\xc9\x39\x94\x8e\x1a\x7c\x01\xee\xa0\x85\x92\xe9\x92\x9a\x6c\x06\x62\x51\xde\xa2\xb2\x93\x82\x4b\x59\xaf\xfd\x0c\x8e\x72\x7b\xfe\x28\x8f\x46\xee\x72\x5b\x89\x01\x29\x52\x91\x6f\x47\x3d\x96\x6a\x83\xa5\x9b\xd5\xcd\x4d\x3a\x49\x82\x3e\xf8\xc8\xcc\x0c\xf0\xc9\xd8\x60\x0d\x20\x4a\xf3\xa7\x08\x4e\x21\x72\x41\x8e\xdc\x21\x88\xae\x31\xdb\x6c\xe1\xbe\x1e\x0d\x96\x73\x4e\xcd\xee\xb1\xa5\xf0\x2a\x48\x70\x59\xd0\xa3\x3b\xa5\xdd\x70\xad\xbc\xb7\xb8\x7a\xaf\xbf\x9e\x7e\x23\xf1\xb0\x93\xba\x49\x43\x77\x6f\xe4\x7d\xc3\x65\x3b\x29\x16\x9f\xe6\x98\x19\xcc\x5d\x29\xc2\xd1\x67\x57\x8c\x9e\x6f\x99\x85\xd0\xb7\x80\x96\x64\x7e\xa6\xcd\x5d\x4a\x55\x52\x93\x0a\xe3\xe3\x4f\x9c\x75\x23\x78\x7b\x9a\xec\x1d\x50\xc2\x9d\x49\x77\x5a\x09\x60\x69\xd2\x6f\x85\xc1\xdb\xb3\x6f\xdd\x32\x64\x2f\x4c\x34\xbb\x22\x39\x60\xeb\x50\x16\xbf\x2c\x90\xed\xa2\xc3\x91\x6b\x27\x5f\x19\x6f\x1b\xf5\x2d\xe1\x0e\x98\xf7\x6f\x9a\xc9\x39\x92\x34\x7f\x82\x93\x95\xa8\x08\x45\x9e\xb4\xd7\x42\x85\x26\x14\x5f\x63\xb6\x16\x6e\xcf\x0e\xed\xe8\xb0\x91\x75\x36\x6c\x0c\xea\xda\x26\xdf\x16\xb5\x25\xe7\xeb\xdc\xfb\xd1\xd4\xeb\xb4\xfa\x36\x0b\x83\xfb\x5c\x51\xaf\xda\xbc\x9f\x6a\x9a\x79\xe2\xf8\xd8\xd1\xcb\x70\x73\x76\xd9\x3b\xba\x0c\xbb\xb3\x8b\xf9\x91\xb1\xe5\x6f\x4e\x2d\xb5\xe7\xa6\x6e\x7d\xbb\xf0\x88\x05\xe7\x0e\x16\x1b\xa3\x00\xd6\x93\x1f\x09\xc7\x4a\xc9\xaf\x0f\x46\x93\x36\x33\xaa\x3f\x29\x2c\xd8\x53\x70\x79\xa4\x1f\x78\xd4\x0e\x2a\xdd\x98\x6d\x8c\x5a\x27\xbb\x67\xb6\x96\x75\xf6\x46\x66\xff\x00\xd6\x4e\x60\x2f\x1d\xed\x26\xae\x17\x44\xce\xbc\x68\x5d\xf3\x1d\x02\x3e\xc4\xa0\x43\xb5\xee\xe1\xf8\x3d\xc9\x1d\x0e\xa5\x2f\xdd\xee\x73\x7a\x93\x71\xba\x43\x5a\xf0\xf9\x0a\xe7\x94\x54\x3c\x1f\xf0\xa6\x76\x83\xb5\x7d\xef\x87\xc4\x32\x75\x3f\x7e\xea\xc5\xad\x9b\xa3\x2f\x8e\x26\xed\xa6\x43\x5e\xdc\x36\xa5\xdd\x03\xf2\x0a\x9f\x4c\x9c\x38\x34\x0f\x7d\x85\xf7\xc2\x27\xf8\xd9\x85\x67\x8b\xb6\x28\xaa\xa6\x28\x1b\x82\x09\x5f\x18\x1d\xab\x76\x50\x48\xf8\x8c\x74\x7c\xb0\xf9\x66\x80\x0b\xa0\xf3\x39\x8a\x3c\xde\x94\x8c\xc2\x8b\x12\xf7\x0a\xdd\xd3\x53\xfe\x0a\x00\x00\xff\xff\x3d\x02\xd1\x96\xf6\x11\x00\x00") +var _templateDialectSqlDecodeTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x56\xdb\x6e\xdb\x38\x10\x7d\xb6\xbe\x62\x2a\x38\x81\x65\x38\xb4\x53\x2c\x16\xd8\x14\x59\xa0\xc8\x05\xd0\x62\x91\x2d\x72\xe9\x4b\x11\x2c\x18\x69\x18\x73\x43\x91\x0e\x49\xe5\x02\x41\xff\xbe\xe0\x45\xb6\x94\xc4\x4d\xfb\xd0\x37\x53\x43\x9e\x99\x39\xe7\xcc\xc0\x4d\x33\x9f\x26\x47\x6a\xf5\xac\xf9\xed\xd2\xc2\xc7\xc5\xfe\x1f\x7b\x2b\x8d\x06\xa5\x85\x53\x5a\xe0\x8d\x52\x77\x90\xcb\x82\xc0\x67\x21\xc0\x5f\x32\xe0\xe2\xfa\x01\x4b\x92\x5c\x2e\xb9\x01\xa3\x6a\x5d\x20\x14\xaa\x44\xe0\x06\x04\x2f\x50\x1a\x2c\xa1\x96\x25\x6a\xb0\x4b\x84\xcf\x2b\x5a\x2c\x11\x3e\x92\x45\x17\x05\xa6\x6a\x59\x26\x5c\xfa\xf8\xdf\xf9\xd1\xc9\xd9\xc5\x09\x30\x2e\x10\xe2\x37\xad\x94\x85\x92\x6b\x2c\xac\xd2\xcf\xa0\x18\xd8\x5e\x32\xab\x11\x49\x32\x9d\xb7\x6d\x92\x34\x0d\x94\xc8\xb8\x44\x48\x4b\x4e\x05\x16\x76\x6e\xee\xc5\xbc\x44\x57\xd1\x5c\x49\x4c\xa1\x6d\xdd\xad\xb1\xc6\x02\xf9\x03\x6a\x38\x38\x84\x31\x39\xef\x4e\x0e\x64\x3e\x07\x53\x50\xf9\x95\x8a\x1a\x5d\x87\xb6\xd6\xd2\xf8\x42\xec\xf3\x0a\x0d\x30\xa5\xfd\x05\xc9\xe5\x2d\x3c\x84\x5b\x4c\xab\x0a\xcc\xbd\x20\xe7\xea\xd1\x90\x84\xd5\xb2\x80\xc9\xd4\x25\x22\x67\xb4\x42\x68\xdb\xac\x07\x3a\xc9\xe0\xdb\x35\x97\x16\x35\xa3\x05\x36\x2d\x34\xc9\x28\xe4\x79\xfd\x7d\xb4\xdb\x34\xc0\x19\x48\x65\x61\x4c\xf2\x63\x72\x65\x50\x1f\xfb\x26\x4b\x68\x5b\x97\xf3\xac\x16\x22\x97\xf6\xf7\xdf\x9a\x06\x50\x18\x97\xcd\x67\xce\x8f\x7d\xe8\xf2\x79\x15\x3f\xa1\x74\x4f\x9a\x76\x96\x8c\x46\x4d\xb3\x07\x9a\xca\x5b\x84\xf1\xbf\x33\x18\xb3\x40\xc4\x29\x47\x51\x1a\x47\xc3\x28\x64\x1e\xb3\x01\xc6\xfa\x69\x80\x4a\x46\x6d\x12\x18\xa3\xc6\xf0\xdb\x8e\xb3\x70\x08\x9c\x45\x82\xec\x92\x5a\x78\x44\x8d\x91\x50\x2c\x87\x9c\xc1\x84\x32\x8b\x1b\x62\x33\x07\x6a\x95\x87\xe8\xd3\x08\xcc\x57\xd8\x51\x3c\x90\xb2\x6d\xe1\x05\xe5\xfd\xaa\x26\xb1\x12\x42\x48\x8f\xe2\x0c\x50\x6b\xa5\x3d\xd3\x9c\x41\x35\x03\xe9\x98\x10\x28\xe3\xfd\x6c\xe6\x0f\x1e\xf7\x0b\x2d\xee\xe8\xad\x83\x26\x47\x4a\xd4\x95\x34\xd9\x27\xa8\xe0\xc3\x21\x48\x0f\xd0\x89\xc8\x2a\x4b\x4e\x1c\x2c\x9b\xa4\x15\x37\x15\xb5\xc5\x12\x64\x5d\xdd\xa0\x76\xee\x75\x3d\x46\x5e\x0e\x60\xa7\x74\xef\x77\xca\x74\xe6\x93\x67\xc9\x68\xd4\x46\x8e\x39\x03\x2a\xcb\xd7\xaa\x4f\x94\x0e\x1f\x73\x73\x61\xb5\x73\x61\x3c\x5d\x5d\xe5\xc7\x59\x14\xcf\x01\x3c\x72\xbb\x04\x7c\xb2\x4e\xac\x31\xa4\x79\xf9\x94\xc2\x02\x52\x2f\x72\xea\x1f\x41\x7a\x8e\x45\x3a\xe0\xd0\x3d\x1e\x35\x0d\x58\xac\x56\x82\xda\xb7\x47\x89\x05\x08\xd2\x4b\xd6\x39\x22\x1c\x82\x0d\x5d\xcc\x37\x3a\x03\x75\xe7\x78\x0d\x5d\x7f\x5b\x5c\x93\xc9\x74\x60\x5d\xd7\xb7\x13\xe0\x83\xba\x0b\x54\xbe\xc5\x65\x2d\xf1\x69\x85\x85\xc5\xd2\x8f\x22\xec\x5c\xfa\x61\xf4\xc5\x00\x77\x14\x7a\x7c\x8f\x15\xeb\x1a\xb4\xe6\x1a\x3e\x84\x30\x4f\x43\x02\xdb\xd6\x58\x5d\x28\xf9\x40\x4e\x95\xae\xa8\xcd\xa5\x0d\xfa\x13\x5f\xdd\x0c\xf6\x17\xd9\xeb\xe9\x8a\x53\xd1\xbf\x99\xad\xc7\xec\xc5\xa0\x8c\xa2\xfd\xd6\x1c\xec\x1f\x5c\x0f\xc7\x90\x6f\x19\xc3\x6d\x4a\x8e\xf9\x46\x4a\xf6\xcb\x84\xec\x0e\x51\x0e\xc9\x45\xe2\x37\x68\x0c\xbc\xb3\x72\x23\xbc\x43\x70\x68\x63\x1e\xfa\xbb\x28\xd4\x0a\x49\x5e\x3e\xc1\xde\x3a\xc4\xfa\x21\xdf\x57\x2f\xa8\xd1\xf6\xc3\xe7\x58\x6c\x82\x4e\x4c\x46\x72\xf3\xd7\xc5\x3f\x67\xa1\x56\xce\xe0\x2d\xd7\x39\xd9\x38\xb4\xad\x33\xdf\xab\xd5\x96\x7d\xda\x78\xef\x67\xad\x17\xc1\xc2\xd6\xe9\x5c\xd8\xcb\xe7\x87\x3a\x98\xa7\x2b\xcd\x2f\x0d\x2e\x60\x77\xd7\xaf\x97\x69\x30\x2e\xfc\x09\x8b\x50\x02\x67\x6e\x31\xb9\xe2\xff\x33\x4a\x92\x2b\x59\x51\x6d\x96\x54\xc4\x9b\x33\xd8\x0d\xde\xb6\xce\xd6\x21\xff\x85\xd5\x75\x61\x03\x73\xbe\x1f\x07\x10\xd3\x7c\x67\xa4\x22\xf0\x5b\xad\x1c\xc0\xce\x43\x3a\x73\x38\xeb\x91\x8a\x9c\x6f\xe6\xdb\xcb\x23\x6b\x21\x3c\x2d\x4e\xa3\x1e\xad\x7b\x3f\x23\xc7\x1a\xe4\xd7\x8b\x11\x6d\xb3\xa4\xe6\x8b\x46\xc6\x9f\x7a\xc9\x53\x73\x2f\xd2\x38\x0d\x2f\x34\x23\x5f\xa9\xe0\x65\xe4\x72\xe3\xbc\x33\x2e\x04\xbd\x11\xdd\xbe\xeb\xb6\xce\x56\x65\xe0\x10\x24\x3e\x4e\x42\xa8\x73\x5f\x78\x39\x7d\xff\xe9\xd0\xb8\x21\x90\xfa\xf2\xd2\xcd\xcc\x0f\x16\xf0\x8f\x14\xf4\xa3\xa8\x5b\x76\xfc\x16\x73\x77\x4c\xbd\x97\x3d\x78\xfa\xe5\xc6\xe9\xac\x16\xce\xbd\x9f\xef\xec\x9c\x8a\xca\xe7\xee\x7f\x5e\x7c\xf1\x7f\x00\x00\x00\xff\xff\xb2\xfe\xca\x7e\xdc\x0a\x00\x00") func templateDialectSqlDecodeTmplBytes() ([]byte, error) { return bindataRead( @@ -616,7 +616,7 @@ func templateDialectSqlDecodeTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/decode.tmpl", size: 4598, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/dialect/sql/decode.tmpl", size: 2780, 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/decode.tmpl b/entc/gen/template/dialect/sql/decode.tmpl index baf36d9e0..768c7c87f 100644 --- a/entc/gen/template/dialect/sql/decode.tmpl +++ b/entc/gen/template/dialect/sql/decode.tmpl @@ -7,44 +7,6 @@ in the LICENSE file in the root directory of this source tree. {{ define "dialect/sql/decode/one" }} {{ $receiver := $.Receiver }} -// FromRows scans the sql response data into {{ $.Name }}. -func ({{ $receiver }} *{{ $.Name }}) FromRows(rows *sql.Rows) error { - {{- $scan := print "scan" $receiver }} - var {{ $scan }} struct { - ID {{ if $.ID.IsString }}int{{ else }}{{ $.ID.Type }}{{ end }} - {{ range $_, $f := $.Fields }} - {{- $f.StructField }} {{ $f.NullType }} - {{ end }} - } - // the order here should be the same as in the `{{ $.Package }}.Columns`. - if err := rows.Scan( - &{{ $scan }}.ID, - {{- range $_, $f := $.Fields }} - &{{ $scan }}.{{ $f.StructField }}, - {{- end }} - ); err != nil { - return err - } - {{ $receiver }}.ID = {{ if $.ID.IsString }}strconv.Itoa({{ $scan }}.ID){{ else }}{{ $scan }}.ID{{ end }} - {{- range $_, $f := $.Fields }} - {{- if $f.IsJSON }} - if value := {{ $scan }}.{{ $f.StructField }}; len(value) > 0 { - if err := json.Unmarshal(value, &{{ $receiver }}.{{ $f.StructField }}); err != nil { - return fmt.Errorf("unmarshal field {{ $f.Name }}: %v", err) - } - } - {{- else if $f.Nillable }} - if {{ $scan }}.{{ $f.StructField }}.Valid { - {{ $receiver }}.{{ $f.StructField }} = new({{ $f.Type }}) - *{{ $receiver }}.{{ $f.StructField }} = {{ printf "%s.%s" $scan $f.StructField | $f.NullTypeField }} - } - {{- else }} - {{ $receiver }}.{{ $f.StructField }} = {{ printf "%s.%s" $scan $f.StructField | $f.NullTypeField }} - {{- end }} - {{- end }} - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*{{ $.Name }}) scanValues() []interface{} { return []interface{} { @@ -115,19 +77,4 @@ func ({{ $receiver }} *{{ $.Name }}) assignValues(values ...interface{}) error { {{- end }} {{ define "dialect/sql/decode/many" }} -{{ $receiver := $.Receiver }} -{{ $slice := $.Scope.Slice }} - -// FromRows scans the sql response data into {{ $slice }}. -func ({{ $receiver }} *{{ $slice }}) FromRows(rows *sql.Rows) error { - for rows.Next() { - {{- $scan := print "scan" $receiver }} - {{ $scan }} := &{{ $.Name }}{} - if err := {{ $scan }}.FromRows(rows); err != nil { - return err - } - *{{ $receiver }} = append(*{{ $receiver }}, {{ $scan }}) - } - return nil -} {{ end }} diff --git a/entc/integration/config/ent/user.go b/entc/integration/config/ent/user.go index 19adf7e1f..1c0c6a0bb 100644 --- a/entc/integration/config/ent/user.go +++ b/entc/integration/config/ent/user.go @@ -21,21 +21,6 @@ type User struct { ID int `json:"id,omitempty"` } -// FromRows scans the sql response data into User. -func (u *User) FromRows(rows *sql.Rows) error { - var scanu struct { - ID int - } - // the order here should be the same as in the `user.Columns`. - if err := rows.Scan( - &scanu.ID, - ); err != nil { - return err - } - u.ID = scanu.ID - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -88,18 +73,6 @@ func (u *User) String() 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() { - scanu := &User{} - if err := scanu.FromRows(rows); err != nil { - return err - } - *u = append(*u, scanu) - } - return nil -} - func (u Users) config(cfg config) { for _i := range u { u[_i].config = cfg diff --git a/entc/integration/customid/ent/blob.go b/entc/integration/customid/ent/blob.go index 9b4271aad..db9498529 100644 --- a/entc/integration/customid/ent/blob.go +++ b/entc/integration/customid/ent/blob.go @@ -10,7 +10,6 @@ import ( "fmt" "strings" - "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/entc/integration/customid/ent/blob" "github.com/google/uuid" ) @@ -24,24 +23,6 @@ type Blob struct { UUID uuid.UUID `json:"uuid,omitempty"` } -// FromRows scans the sql response data into Blob. -func (b *Blob) FromRows(rows *sql.Rows) error { - var scanb struct { - ID uuid.UUID - UUID uuid.UUID - } - // the order here should be the same as in the `blob.Columns`. - if err := rows.Scan( - &scanb.ID, - &scanb.UUID, - ); err != nil { - return err - } - b.ID = scanb.ID - b.UUID = scanb.UUID - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Blob) scanValues() []interface{} { return []interface{}{ @@ -102,18 +83,6 @@ func (b *Blob) String() string { // Blobs is a parsable slice of Blob. type Blobs []*Blob -// FromRows scans the sql response data into Blobs. -func (b *Blobs) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanb := &Blob{} - if err := scanb.FromRows(rows); err != nil { - return err - } - *b = append(*b, scanb) - } - return nil -} - func (b Blobs) config(cfg config) { for _i := range b { b[_i].config = cfg diff --git a/entc/integration/customid/ent/group.go b/entc/integration/customid/ent/group.go index 6579dce50..6db6a8c15 100644 --- a/entc/integration/customid/ent/group.go +++ b/entc/integration/customid/ent/group.go @@ -21,21 +21,6 @@ type Group struct { ID int `json:"id,omitempty"` } -// FromRows scans the sql response data into Group. -func (gr *Group) FromRows(rows *sql.Rows) error { - var scangr struct { - ID int - } - // the order here should be the same as in the `group.Columns`. - if err := rows.Scan( - &scangr.ID, - ); err != nil { - return err - } - gr.ID = scangr.ID - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Group) scanValues() []interface{} { return []interface{}{ @@ -93,18 +78,6 @@ func (gr *Group) String() string { // Groups is a parsable slice of Group. type Groups []*Group -// FromRows scans the sql response data into Groups. -func (gr *Groups) FromRows(rows *sql.Rows) error { - for rows.Next() { - scangr := &Group{} - if err := scangr.FromRows(rows); err != nil { - return err - } - *gr = append(*gr, scangr) - } - return nil -} - func (gr Groups) config(cfg config) { for _i := range gr { gr[_i].config = cfg diff --git a/entc/integration/customid/ent/user.go b/entc/integration/customid/ent/user.go index 9785d2f18..ad079d2d1 100644 --- a/entc/integration/customid/ent/user.go +++ b/entc/integration/customid/ent/user.go @@ -21,21 +21,6 @@ type User struct { ID int `json:"id,omitempty"` } -// FromRows scans the sql response data into User. -func (u *User) FromRows(rows *sql.Rows) error { - var scanu struct { - ID int - } - // the order here should be the same as in the `user.Columns`. - if err := rows.Scan( - &scanu.ID, - ); err != nil { - return err - } - u.ID = scanu.ID - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -93,18 +78,6 @@ func (u *User) String() 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() { - scanu := &User{} - if err := scanu.FromRows(rows); err != nil { - return err - } - *u = append(*u, scanu) - } - return nil -} - func (u Users) config(cfg config) { for _i := range u { u[_i].config = cfg diff --git a/entc/integration/ent/card.go b/entc/integration/ent/card.go index 3ca4597de..10f83fca1 100644 --- a/entc/integration/ent/card.go +++ b/entc/integration/ent/card.go @@ -34,33 +34,6 @@ type Card struct { StaticField string `json:"boring,omitempty"` } -// FromRows scans the sql response data into Card. -func (c *Card) FromRows(rows *sql.Rows) error { - var scanc struct { - ID int - CreateTime sql.NullTime - UpdateTime sql.NullTime - Number sql.NullString - Name sql.NullString - } - // the order here should be the same as in the `card.Columns`. - if err := rows.Scan( - &scanc.ID, - &scanc.CreateTime, - &scanc.UpdateTime, - &scanc.Number, - &scanc.Name, - ); err != nil { - return err - } - c.ID = strconv.Itoa(scanc.ID) - c.CreateTime = scanc.CreateTime.Time - c.UpdateTime = scanc.UpdateTime.Time - c.Number = scanc.Number.String - c.Name = scanc.Name.String - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Card) scanValues() []interface{} { return []interface{}{ @@ -156,18 +129,6 @@ func (c *Card) id() int { // Cards is a parsable slice of Card. type Cards []*Card -// FromRows scans the sql response data into Cards. -func (c *Cards) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanc := &Card{} - if err := scanc.FromRows(rows); err != nil { - return err - } - *c = append(*c, scanc) - } - return nil -} - func (c Cards) config(cfg config) { for _i := range c { c[_i].config = cfg diff --git a/entc/integration/ent/comment.go b/entc/integration/ent/comment.go index dd60f9bf9..b5e25816d 100644 --- a/entc/integration/ent/comment.go +++ b/entc/integration/ent/comment.go @@ -28,33 +28,6 @@ type Comment struct { NillableInt *int `json:"nillable_int,omitempty"` } -// FromRows scans the sql response data into Comment. -func (c *Comment) FromRows(rows *sql.Rows) error { - var scanc struct { - ID int - UniqueInt sql.NullInt64 - UniqueFloat sql.NullFloat64 - NillableInt sql.NullInt64 - } - // the order here should be the same as in the `comment.Columns`. - if err := rows.Scan( - &scanc.ID, - &scanc.UniqueInt, - &scanc.UniqueFloat, - &scanc.NillableInt, - ); err != nil { - return err - } - c.ID = strconv.Itoa(scanc.ID) - c.UniqueInt = int(scanc.UniqueInt.Int64) - c.UniqueFloat = scanc.UniqueFloat.Float64 - if scanc.NillableInt.Valid { - c.NillableInt = new(int) - *c.NillableInt = int(scanc.NillableInt.Int64) - } - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Comment) scanValues() []interface{} { return []interface{}{ @@ -140,18 +113,6 @@ func (c *Comment) id() int { // Comments is a parsable slice of Comment. type Comments []*Comment -// FromRows scans the sql response data into Comments. -func (c *Comments) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanc := &Comment{} - if err := scanc.FromRows(rows); err != nil { - return err - } - *c = append(*c, scanc) - } - return nil -} - func (c Comments) config(cfg config) { for _i := range c { c[_i].config = cfg diff --git a/entc/integration/ent/fieldtype.go b/entc/integration/ent/fieldtype.go index 8961516ef..0f2162e84 100644 --- a/entc/integration/ent/fieldtype.go +++ b/entc/integration/ent/fieldtype.go @@ -56,87 +56,6 @@ type FieldType struct { State fieldtype.State `json:"state,omitempty"` } -// FromRows scans the sql response data into FieldType. -func (ft *FieldType) FromRows(rows *sql.Rows) error { - var scanft struct { - ID int - Int sql.NullInt64 - Int8 sql.NullInt64 - Int16 sql.NullInt64 - Int32 sql.NullInt64 - Int64 sql.NullInt64 - OptionalInt sql.NullInt64 - OptionalInt8 sql.NullInt64 - OptionalInt16 sql.NullInt64 - OptionalInt32 sql.NullInt64 - OptionalInt64 sql.NullInt64 - NillableInt sql.NullInt64 - NillableInt8 sql.NullInt64 - NillableInt16 sql.NullInt64 - NillableInt32 sql.NullInt64 - NillableInt64 sql.NullInt64 - ValidateOptionalInt32 sql.NullInt64 - State sql.NullString - } - // the order here should be the same as in the `fieldtype.Columns`. - if err := rows.Scan( - &scanft.ID, - &scanft.Int, - &scanft.Int8, - &scanft.Int16, - &scanft.Int32, - &scanft.Int64, - &scanft.OptionalInt, - &scanft.OptionalInt8, - &scanft.OptionalInt16, - &scanft.OptionalInt32, - &scanft.OptionalInt64, - &scanft.NillableInt, - &scanft.NillableInt8, - &scanft.NillableInt16, - &scanft.NillableInt32, - &scanft.NillableInt64, - &scanft.ValidateOptionalInt32, - &scanft.State, - ); err != nil { - return err - } - ft.ID = strconv.Itoa(scanft.ID) - ft.Int = int(scanft.Int.Int64) - ft.Int8 = int8(scanft.Int8.Int64) - ft.Int16 = int16(scanft.Int16.Int64) - ft.Int32 = int32(scanft.Int32.Int64) - ft.Int64 = scanft.Int64.Int64 - ft.OptionalInt = int(scanft.OptionalInt.Int64) - ft.OptionalInt8 = int8(scanft.OptionalInt8.Int64) - ft.OptionalInt16 = int16(scanft.OptionalInt16.Int64) - ft.OptionalInt32 = int32(scanft.OptionalInt32.Int64) - ft.OptionalInt64 = scanft.OptionalInt64.Int64 - if scanft.NillableInt.Valid { - ft.NillableInt = new(int) - *ft.NillableInt = int(scanft.NillableInt.Int64) - } - if scanft.NillableInt8.Valid { - ft.NillableInt8 = new(int8) - *ft.NillableInt8 = int8(scanft.NillableInt8.Int64) - } - if scanft.NillableInt16.Valid { - ft.NillableInt16 = new(int16) - *ft.NillableInt16 = int16(scanft.NillableInt16.Int64) - } - if scanft.NillableInt32.Valid { - ft.NillableInt32 = new(int32) - *ft.NillableInt32 = int32(scanft.NillableInt32.Int64) - } - if scanft.NillableInt64.Valid { - ft.NillableInt64 = new(int64) - *ft.NillableInt64 = scanft.NillableInt64.Int64 - } - ft.ValidateOptionalInt32 = int32(scanft.ValidateOptionalInt32.Int64) - ft.State = fieldtype.State(scanft.State.String) - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*FieldType) scanValues() []interface{} { return []interface{}{ @@ -346,18 +265,6 @@ func (ft *FieldType) id() int { // FieldTypes is a parsable slice of FieldType. type FieldTypes []*FieldType -// FromRows scans the sql response data into FieldTypes. -func (ft *FieldTypes) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanft := &FieldType{} - if err := scanft.FromRows(rows); err != nil { - return err - } - *ft = append(*ft, scanft) - } - return nil -} - func (ft FieldTypes) config(cfg config) { for _i := range ft { ft[_i].config = cfg diff --git a/entc/integration/ent/file.go b/entc/integration/ent/file.go index b67e2c795..a1eac32fd 100644 --- a/entc/integration/ent/file.go +++ b/entc/integration/ent/file.go @@ -30,36 +30,6 @@ type File struct { Group string `json:"group,omitempty"` } -// FromRows scans the sql response data into File. -func (f *File) FromRows(rows *sql.Rows) error { - var scanf struct { - ID int - Size sql.NullInt64 - Name sql.NullString - User sql.NullString - Group sql.NullString - } - // the order here should be the same as in the `file.Columns`. - if err := rows.Scan( - &scanf.ID, - &scanf.Size, - &scanf.Name, - &scanf.User, - &scanf.Group, - ); err != nil { - return err - } - f.ID = strconv.Itoa(scanf.ID) - f.Size = int(scanf.Size.Int64) - f.Name = scanf.Name.String - if scanf.User.Valid { - f.User = new(string) - *f.User = scanf.User.String - } - f.Group = scanf.Group.String - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*File) scanValues() []interface{} { return []interface{}{ @@ -163,18 +133,6 @@ func (f *File) id() int { // Files is a parsable slice of File. type Files []*File -// FromRows scans the sql response data into Files. -func (f *Files) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanf := &File{} - if err := scanf.FromRows(rows); err != nil { - return err - } - *f = append(*f, scanf) - } - return nil -} - func (f Files) config(cfg config) { for _i := range f { f[_i].config = cfg diff --git a/entc/integration/ent/filetype.go b/entc/integration/ent/filetype.go index 5d682cb5c..9e97e1871 100644 --- a/entc/integration/ent/filetype.go +++ b/entc/integration/ent/filetype.go @@ -24,24 +24,6 @@ type FileType struct { Name string `json:"name,omitempty"` } -// FromRows scans the sql response data into FileType. -func (ft *FileType) FromRows(rows *sql.Rows) error { - var scanft struct { - ID int - Name sql.NullString - } - // the order here should be the same as in the `filetype.Columns`. - if err := rows.Scan( - &scanft.ID, - &scanft.Name, - ); err != nil { - return err - } - ft.ID = strconv.Itoa(scanft.ID) - ft.Name = scanft.Name.String - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*FileType) scanValues() []interface{} { return []interface{}{ @@ -113,18 +95,6 @@ func (ft *FileType) id() int { // FileTypes is a parsable slice of FileType. type FileTypes []*FileType -// FromRows scans the sql response data into FileTypes. -func (ft *FileTypes) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanft := &FileType{} - if err := scanft.FromRows(rows); err != nil { - return err - } - *ft = append(*ft, scanft) - } - return nil -} - func (ft FileTypes) config(cfg config) { for _i := range ft { ft[_i].config = cfg diff --git a/entc/integration/ent/group.go b/entc/integration/ent/group.go index 1b497dbde..158a04b93 100644 --- a/entc/integration/ent/group.go +++ b/entc/integration/ent/group.go @@ -33,39 +33,6 @@ type Group struct { Name string `json:"name,omitempty"` } -// FromRows scans the sql response data into Group. -func (gr *Group) FromRows(rows *sql.Rows) error { - var scangr struct { - ID int - Active sql.NullBool - Expire sql.NullTime - Type sql.NullString - MaxUsers sql.NullInt64 - Name sql.NullString - } - // the order here should be the same as in the `group.Columns`. - if err := rows.Scan( - &scangr.ID, - &scangr.Active, - &scangr.Expire, - &scangr.Type, - &scangr.MaxUsers, - &scangr.Name, - ); err != nil { - return err - } - gr.ID = strconv.Itoa(scangr.ID) - gr.Active = scangr.Active.Bool - gr.Expire = scangr.Expire.Time - if scangr.Type.Valid { - gr.Type = new(string) - *gr.Type = scangr.Type.String - } - gr.MaxUsers = int(scangr.MaxUsers.Int64) - gr.Name = scangr.Name.String - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Group) scanValues() []interface{} { return []interface{}{ @@ -187,18 +154,6 @@ func (gr *Group) id() int { // Groups is a parsable slice of Group. type Groups []*Group -// FromRows scans the sql response data into Groups. -func (gr *Groups) FromRows(rows *sql.Rows) error { - for rows.Next() { - scangr := &Group{} - if err := scangr.FromRows(rows); err != nil { - return err - } - *gr = append(*gr, scangr) - } - return nil -} - func (gr Groups) config(cfg config) { for _i := range gr { gr[_i].config = cfg diff --git a/entc/integration/ent/groupinfo.go b/entc/integration/ent/groupinfo.go index 9c9b48dfd..b212a173d 100644 --- a/entc/integration/ent/groupinfo.go +++ b/entc/integration/ent/groupinfo.go @@ -26,27 +26,6 @@ type GroupInfo struct { MaxUsers int `json:"max_users,omitempty"` } -// FromRows scans the sql response data into GroupInfo. -func (gi *GroupInfo) FromRows(rows *sql.Rows) error { - var scangi struct { - ID int - Desc sql.NullString - MaxUsers sql.NullInt64 - } - // the order here should be the same as in the `groupinfo.Columns`. - if err := rows.Scan( - &scangi.ID, - &scangi.Desc, - &scangi.MaxUsers, - ); err != nil { - return err - } - gi.ID = strconv.Itoa(scangi.ID) - gi.Desc = scangi.Desc.String - gi.MaxUsers = int(scangi.MaxUsers.Int64) - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*GroupInfo) scanValues() []interface{} { return []interface{}{ @@ -126,18 +105,6 @@ func (gi *GroupInfo) id() int { // GroupInfos is a parsable slice of GroupInfo. type GroupInfos []*GroupInfo -// FromRows scans the sql response data into GroupInfos. -func (gi *GroupInfos) FromRows(rows *sql.Rows) error { - for rows.Next() { - scangi := &GroupInfo{} - if err := scangi.FromRows(rows); err != nil { - return err - } - *gi = append(*gi, scangi) - } - return nil -} - func (gi GroupInfos) config(cfg config) { for _i := range gi { gi[_i].config = cfg diff --git a/entc/integration/ent/item.go b/entc/integration/ent/item.go index df677b685..39c2bb6ed 100644 --- a/entc/integration/ent/item.go +++ b/entc/integration/ent/item.go @@ -22,21 +22,6 @@ type Item struct { ID string `json:"id,omitempty"` } -// FromRows scans the sql response data into Item. -func (i *Item) FromRows(rows *sql.Rows) error { - var scani struct { - ID int - } - // the order here should be the same as in the `item.Columns`. - if err := rows.Scan( - &scani.ID, - ); err != nil { - return err - } - i.ID = strconv.Itoa(scani.ID) - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Item) scanValues() []interface{} { return []interface{}{ @@ -95,18 +80,6 @@ func (i *Item) id() int { // Items is a parsable slice of Item. type Items []*Item -// FromRows scans the sql response data into Items. -func (i *Items) FromRows(rows *sql.Rows) error { - for rows.Next() { - scani := &Item{} - if err := scani.FromRows(rows); err != nil { - return err - } - *i = append(*i, scani) - } - return nil -} - func (i Items) config(cfg config) { for _i := range i { i[_i].config = cfg diff --git a/entc/integration/ent/node.go b/entc/integration/ent/node.go index 22da6adca..6a764aebe 100644 --- a/entc/integration/ent/node.go +++ b/entc/integration/ent/node.go @@ -24,24 +24,6 @@ type Node struct { Value int `json:"value,omitempty"` } -// FromRows scans the sql response data into Node. -func (n *Node) FromRows(rows *sql.Rows) error { - var scann struct { - ID int - Value sql.NullInt64 - } - // the order here should be the same as in the `node.Columns`. - if err := rows.Scan( - &scann.ID, - &scann.Value, - ); err != nil { - return err - } - n.ID = strconv.Itoa(scann.ID) - n.Value = int(scann.Value.Int64) - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Node) scanValues() []interface{} { return []interface{}{ @@ -118,18 +100,6 @@ func (n *Node) id() int { // Nodes is a parsable slice of Node. type Nodes []*Node -// FromRows scans the sql response data into Nodes. -func (n *Nodes) FromRows(rows *sql.Rows) error { - for rows.Next() { - scann := &Node{} - if err := scann.FromRows(rows); err != nil { - return err - } - *n = append(*n, scann) - } - return nil -} - func (n Nodes) config(cfg config) { for _i := range n { n[_i].config = cfg diff --git a/entc/integration/ent/pet.go b/entc/integration/ent/pet.go index 9e1ec9345..929bc018a 100644 --- a/entc/integration/ent/pet.go +++ b/entc/integration/ent/pet.go @@ -24,24 +24,6 @@ type Pet struct { Name string `json:"name,omitempty"` } -// FromRows scans the sql response data into Pet. -func (pe *Pet) FromRows(rows *sql.Rows) error { - var scanpe struct { - ID int - Name sql.NullString - } - // the order here should be the same as in the `pet.Columns`. - if err := rows.Scan( - &scanpe.ID, - &scanpe.Name, - ); err != nil { - return err - } - pe.ID = strconv.Itoa(scanpe.ID) - pe.Name = scanpe.Name.String - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Pet) scanValues() []interface{} { return []interface{}{ @@ -118,18 +100,6 @@ func (pe *Pet) id() int { // Pets is a parsable slice of Pet. type Pets []*Pet -// FromRows scans the sql response data into Pets. -func (pe *Pets) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanpe := &Pet{} - if err := scanpe.FromRows(rows); err != nil { - return err - } - *pe = append(*pe, scanpe) - } - return nil -} - func (pe Pets) config(cfg config) { for _i := range pe { pe[_i].config = cfg diff --git a/entc/integration/ent/user.go b/entc/integration/ent/user.go index 93b88f7d2..712e2a9b4 100644 --- a/entc/integration/ent/user.go +++ b/entc/integration/ent/user.go @@ -34,39 +34,6 @@ type User struct { Password string `graphql:"-" json:"-"` } -// FromRows scans the sql response data into User. -func (u *User) FromRows(rows *sql.Rows) error { - var scanu struct { - ID int - Age sql.NullInt64 - Name sql.NullString - Last sql.NullString - Nickname sql.NullString - Phone sql.NullString - Password sql.NullString - } - // the order here should be the same as in the `user.Columns`. - if err := rows.Scan( - &scanu.ID, - &scanu.Age, - &scanu.Name, - &scanu.Last, - &scanu.Nickname, - &scanu.Phone, - &scanu.Password, - ); err != nil { - return err - } - u.ID = strconv.Itoa(scanu.ID) - u.Age = int(scanu.Age.Int64) - u.Name = scanu.Name.String - u.Last = scanu.Last.String - u.Nickname = scanu.Nickname.String - u.Phone = scanu.Phone.String - u.Password = scanu.Password.String - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -227,18 +194,6 @@ func (u *User) id() int { // 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() { - scanu := &User{} - if err := scanu.FromRows(rows); err != nil { - return err - } - *u = append(*u, scanu) - } - return nil -} - func (u Users) config(cfg config) { for _i := range u { u[_i].config = cfg diff --git a/entc/integration/idtype/ent/user.go b/entc/integration/idtype/ent/user.go index 8c5493b20..04cc0e9ba 100644 --- a/entc/integration/idtype/ent/user.go +++ b/entc/integration/idtype/ent/user.go @@ -23,24 +23,6 @@ type User struct { Name string `json:"name,omitempty"` } -// FromRows scans the sql response data into User. -func (u *User) FromRows(rows *sql.Rows) error { - var scanu struct { - ID uint64 - Name sql.NullString - } - // the order here should be the same as in the `user.Columns`. - if err := rows.Scan( - &scanu.ID, - &scanu.Name, - ); err != nil { - return err - } - u.ID = scanu.ID - u.Name = scanu.Name.String - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -116,18 +98,6 @@ func (u *User) String() 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() { - scanu := &User{} - if err := scanu.FromRows(rows); err != nil { - return err - } - *u = append(*u, scanu) - } - return nil -} - func (u Users) config(cfg config) { for _i := range u { u[_i].config = cfg diff --git a/entc/integration/json/ent/user.go b/entc/integration/json/ent/user.go index ab8731d58..a5e7ffada 100644 --- a/entc/integration/json/ent/user.go +++ b/entc/integration/json/ent/user.go @@ -36,63 +36,6 @@ type User struct { Strings []string `json:"strings,omitempty"` } -// FromRows scans the sql response data into User. -func (u *User) FromRows(rows *sql.Rows) error { - var scanu struct { - ID int - URL []byte - Raw []byte - Dirs []byte - Ints []byte - Floats []byte - Strings []byte - } - // the order here should be the same as in the `user.Columns`. - if err := rows.Scan( - &scanu.ID, - &scanu.URL, - &scanu.Raw, - &scanu.Dirs, - &scanu.Ints, - &scanu.Floats, - &scanu.Strings, - ); err != nil { - return err - } - u.ID = scanu.ID - if value := scanu.URL; len(value) > 0 { - if err := json.Unmarshal(value, &u.URL); err != nil { - return fmt.Errorf("unmarshal field url: %v", err) - } - } - if value := scanu.Raw; len(value) > 0 { - if err := json.Unmarshal(value, &u.Raw); err != nil { - return fmt.Errorf("unmarshal field raw: %v", err) - } - } - if value := scanu.Dirs; len(value) > 0 { - if err := json.Unmarshal(value, &u.Dirs); err != nil { - return fmt.Errorf("unmarshal field dirs: %v", err) - } - } - if value := scanu.Ints; len(value) > 0 { - if err := json.Unmarshal(value, &u.Ints); err != nil { - return fmt.Errorf("unmarshal field ints: %v", err) - } - } - if value := scanu.Floats; len(value) > 0 { - if err := json.Unmarshal(value, &u.Floats); err != nil { - return fmt.Errorf("unmarshal field floats: %v", err) - } - } - if value := scanu.Strings; len(value) > 0 { - if err := json.Unmarshal(value, &u.Strings); err != nil { - return fmt.Errorf("unmarshal field strings: %v", err) - } - } - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -211,18 +154,6 @@ func (u *User) String() 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() { - scanu := &User{} - if err := scanu.FromRows(rows); err != nil { - return err - } - *u = append(*u, scanu) - } - return nil -} - func (u Users) config(cfg config) { for _i := range u { u[_i].config = cfg diff --git a/entc/integration/migrate/entv1/user.go b/entc/integration/migrate/entv1/user.go index 12b4b8e7d..b15fe3e7e 100644 --- a/entc/integration/migrate/entv1/user.go +++ b/entc/integration/migrate/entv1/user.go @@ -35,42 +35,6 @@ type User struct { State user.State `json:"state,omitempty"` } -// FromRows scans the sql response data into User. -func (u *User) FromRows(rows *sql.Rows) error { - var scanu struct { - ID int - Age sql.NullInt64 - Name sql.NullString - Nickname sql.NullString - Address sql.NullString - Renamed sql.NullString - Blob []byte - State sql.NullString - } - // the order here should be the same as in the `user.Columns`. - if err := rows.Scan( - &scanu.ID, - &scanu.Age, - &scanu.Name, - &scanu.Nickname, - &scanu.Address, - &scanu.Renamed, - &scanu.Blob, - &scanu.State, - ); err != nil { - return err - } - u.ID = scanu.ID - u.Age = int32(scanu.Age.Int64) - u.Name = scanu.Name.String - u.Nickname = scanu.Nickname.String - u.Address = scanu.Address.String - u.Renamed = scanu.Renamed.String - u.Blob = scanu.Blob - u.State = user.State(scanu.State.String) - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -179,18 +143,6 @@ func (u *User) String() 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() { - scanu := &User{} - if err := scanu.FromRows(rows); err != nil { - return err - } - *u = append(*u, scanu) - } - return nil -} - func (u Users) config(cfg config) { for _i := range u { u[_i].config = cfg diff --git a/entc/integration/migrate/entv2/group.go b/entc/integration/migrate/entv2/group.go index 30a25c73b..45755408a 100644 --- a/entc/integration/migrate/entv2/group.go +++ b/entc/integration/migrate/entv2/group.go @@ -21,21 +21,6 @@ type Group struct { ID int `json:"id,omitempty"` } -// FromRows scans the sql response data into Group. -func (gr *Group) FromRows(rows *sql.Rows) error { - var scangr struct { - ID int - } - // the order here should be the same as in the `group.Columns`. - if err := rows.Scan( - &scangr.ID, - ); err != nil { - return err - } - gr.ID = scangr.ID - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Group) scanValues() []interface{} { return []interface{}{ @@ -88,18 +73,6 @@ func (gr *Group) String() string { // Groups is a parsable slice of Group. type Groups []*Group -// FromRows scans the sql response data into Groups. -func (gr *Groups) FromRows(rows *sql.Rows) error { - for rows.Next() { - scangr := &Group{} - if err := scangr.FromRows(rows); err != nil { - return err - } - *gr = append(*gr, scangr) - } - return nil -} - func (gr Groups) config(cfg config) { for _i := range gr { gr[_i].config = cfg diff --git a/entc/integration/migrate/entv2/pet.go b/entc/integration/migrate/entv2/pet.go index 7af1607b1..b1bb4eaa8 100644 --- a/entc/integration/migrate/entv2/pet.go +++ b/entc/integration/migrate/entv2/pet.go @@ -21,21 +21,6 @@ type Pet struct { ID int `json:"id,omitempty"` } -// FromRows scans the sql response data into Pet. -func (pe *Pet) FromRows(rows *sql.Rows) error { - var scanpe struct { - ID int - } - // the order here should be the same as in the `pet.Columns`. - if err := rows.Scan( - &scanpe.ID, - ); err != nil { - return err - } - pe.ID = scanpe.ID - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Pet) scanValues() []interface{} { return []interface{}{ @@ -88,18 +73,6 @@ func (pe *Pet) String() string { // Pets is a parsable slice of Pet. type Pets []*Pet -// FromRows scans the sql response data into Pets. -func (pe *Pets) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanpe := &Pet{} - if err := scanpe.FromRows(rows); err != nil { - return err - } - *pe = append(*pe, scanpe) - } - return nil -} - func (pe Pets) config(cfg config) { for _i := range pe { pe[_i].config = cfg diff --git a/entc/integration/migrate/entv2/user.go b/entc/integration/migrate/entv2/user.go index f374692be..517efeeee 100644 --- a/entc/integration/migrate/entv2/user.go +++ b/entc/integration/migrate/entv2/user.go @@ -39,48 +39,6 @@ type User struct { State user.State `json:"state,omitempty"` } -// FromRows scans the sql response data into User. -func (u *User) FromRows(rows *sql.Rows) error { - var scanu struct { - ID int - Age sql.NullInt64 - Name sql.NullString - Nickname sql.NullString - Phone sql.NullString - Buffer []byte - Title sql.NullString - NewName sql.NullString - Blob []byte - State sql.NullString - } - // the order here should be the same as in the `user.Columns`. - if err := rows.Scan( - &scanu.ID, - &scanu.Age, - &scanu.Name, - &scanu.Nickname, - &scanu.Phone, - &scanu.Buffer, - &scanu.Title, - &scanu.NewName, - &scanu.Blob, - &scanu.State, - ); err != nil { - return err - } - u.ID = scanu.ID - u.Age = int(scanu.Age.Int64) - u.Name = scanu.Name.String - u.Nickname = scanu.Nickname.String - u.Phone = scanu.Phone.String - u.Buffer = scanu.Buffer - u.Title = scanu.Title.String - u.NewName = scanu.NewName.String - u.Blob = scanu.Blob - u.State = user.State(scanu.State.String) - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -205,18 +163,6 @@ func (u *User) String() 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() { - scanu := &User{} - if err := scanu.FromRows(rows); err != nil { - return err - } - *u = append(*u, scanu) - } - return nil -} - func (u Users) config(cfg config) { for _i := range u { u[_i].config = cfg diff --git a/entc/integration/template/ent/group.go b/entc/integration/template/ent/group.go index 30c6086ee..3eca2a2a2 100644 --- a/entc/integration/template/ent/group.go +++ b/entc/integration/template/ent/group.go @@ -23,24 +23,6 @@ type Group struct { MaxUsers int `json:"max_users,omitempty"` } -// FromRows scans the sql response data into Group. -func (gr *Group) FromRows(rows *sql.Rows) error { - var scangr struct { - ID int - MaxUsers sql.NullInt64 - } - // the order here should be the same as in the `group.Columns`. - if err := rows.Scan( - &scangr.ID, - &scangr.MaxUsers, - ); err != nil { - return err - } - gr.ID = scangr.ID - gr.MaxUsers = int(scangr.MaxUsers.Int64) - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Group) scanValues() []interface{} { return []interface{}{ @@ -101,18 +83,6 @@ func (gr *Group) String() string { // Groups is a parsable slice of Group. type Groups []*Group -// FromRows scans the sql response data into Groups. -func (gr *Groups) FromRows(rows *sql.Rows) error { - for rows.Next() { - scangr := &Group{} - if err := scangr.FromRows(rows); err != nil { - return err - } - *gr = append(*gr, scangr) - } - return nil -} - func (gr Groups) config(cfg config) { for _i := range gr { gr[_i].config = cfg diff --git a/entc/integration/template/ent/pet.go b/entc/integration/template/ent/pet.go index 91f70451e..87d123330 100644 --- a/entc/integration/template/ent/pet.go +++ b/entc/integration/template/ent/pet.go @@ -26,30 +26,6 @@ type Pet struct { LicensedAt *time.Time `json:"licensed_at,omitempty"` } -// FromRows scans the sql response data into Pet. -func (pe *Pet) FromRows(rows *sql.Rows) error { - var scanpe struct { - ID int - Age sql.NullInt64 - LicensedAt sql.NullTime - } - // the order here should be the same as in the `pet.Columns`. - if err := rows.Scan( - &scanpe.ID, - &scanpe.Age, - &scanpe.LicensedAt, - ); err != nil { - return err - } - pe.ID = scanpe.ID - pe.Age = int(scanpe.Age.Int64) - if scanpe.LicensedAt.Valid { - pe.LicensedAt = new(time.Time) - *pe.LicensedAt = scanpe.LicensedAt.Time - } - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*Pet) scanValues() []interface{} { return []interface{}{ @@ -126,18 +102,6 @@ func (pe *Pet) String() string { // Pets is a parsable slice of Pet. type Pets []*Pet -// FromRows scans the sql response data into Pets. -func (pe *Pets) FromRows(rows *sql.Rows) error { - for rows.Next() { - scanpe := &Pet{} - if err := scanpe.FromRows(rows); err != nil { - return err - } - *pe = append(*pe, scanpe) - } - return nil -} - func (pe Pets) config(cfg config) { for _i := range pe { pe[_i].config = cfg diff --git a/entc/integration/template/ent/user.go b/entc/integration/template/ent/user.go index 3eb57f7d0..ef4c20058 100644 --- a/entc/integration/template/ent/user.go +++ b/entc/integration/template/ent/user.go @@ -23,24 +23,6 @@ type User struct { Name string `json:"name,omitempty"` } -// FromRows scans the sql response data into User. -func (u *User) FromRows(rows *sql.Rows) error { - var scanu struct { - ID int - Name sql.NullString - } - // the order here should be the same as in the `user.Columns`. - if err := rows.Scan( - &scanu.ID, - &scanu.Name, - ); err != nil { - return err - } - u.ID = scanu.ID - u.Name = scanu.Name.String - return nil -} - // scanValues returns the types for scanning values from sql.Rows. func (*User) scanValues() []interface{} { return []interface{}{ @@ -111,18 +93,6 @@ func (u *User) String() 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() { - scanu := &User{} - if err := scanu.FromRows(rows); err != nil { - return err - } - *u = append(*u, scanu) - } - return nil -} - func (u Users) config(cfg config) { for _i := range u { u[_i].config = cfg