diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index 5c35c2b88..d2ceb3b85 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -690,7 +690,7 @@ func templateDialectSqlDeleteTmpl() (*asset, error) { return a, nil } -var _templateDialectSqlEntqlTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x57\x5f\x4f\xdd\x3a\x12\x7f\x4e\x3e\xc5\x6c\x84\xaa\x04\x9d\xe6\x74\xfb\xb6\xac\x78\xa0\x40\xb7\x47\xbb\x54\x6c\x41\xea\x03\xaa\xae\x4c\x32\x39\xb1\x48\x9c\xd4\xf6\xa1\x42\x51\xbe\xfb\x95\xc7\x4e\xe2\x84\xc3\x29\xe8\xea\x56\x2a\x04\x7b\xfe\xfe\x7e\x93\x99\x49\xd7\xad\x8f\xc3\xf3\xa6\x7d\x92\x7c\x5b\x6a\xf8\xf8\xe1\x9f\xff\x7a\xdf\x4a\x54\x28\x34\x7c\x66\x19\xde\x37\xcd\x03\x6c\x44\x96\xc2\x59\x55\x01\x09\x29\x30\xf7\xf2\x11\xf3\x34\xbc\x2d\xb9\x02\xd5\xec\x64\x86\x90\x35\x39\x02\x57\x50\xf1\x0c\x85\xc2\x1c\x76\x22\x47\x09\xba\x44\x38\x6b\x59\x56\x22\x7c\x4c\x3f\x0c\xb7\x50\x34\x3b\x91\x87\x5c\xd0\xfd\xff\x36\xe7\x97\x5f\x6f\x2e\xa1\xe0\x15\x82\x3b\x93\x4d\xa3\x21\xe7\x12\x33\xdd\xc8\x27\x68\x0a\xd0\x9e\x33\x2d\x11\xd3\xf0\x78\xdd\xf7\x61\xd8\x75\x90\x63\xc1\x05\x42\x94\x73\x56\x61\xa6\xd7\xea\x67\xb5\x46\xa1\x7f\x56\x11\x38\x89\xa3\xf6\x61\x0b\x27\xa7\x70\xcf\x14\xc2\x51\x7a\xde\x88\x82\x6f\xd3\x6b\x96\x3d\xb0\x2d\x1a\xa1\xae\x03\x8d\x75\x5b\x31\x8d\x10\x95\xc8\x72\x94\x11\x1c\x91\x3a\xaf\xdb\x46\x6a\x88\xc3\x20\x32\x96\x9e\x2b\xaf\x5b\x89\x39\xcf\x98\xc6\x28\x0c\xba\xee\x3d\x48\x26\xb6\x08\x47\xc2\x78\x3c\x4a\xbf\x36\x39\x2a\x63\x29\x78\xd1\x80\x39\x16\xde\x81\xb3\x83\x22\xa7\x08\x82\x68\xcb\x75\xb9\xbb\x4f\xb3\xa6\x5e\x17\x8e\x17\x93\xe1\xda\xcb\x38\x7a\x9d\x98\xf9\xbf\x95\xac\x2d\x0f\xc9\x5b\xf0\x0e\x08\xa8\xac\xc4\x9a\xad\x0b\x8e\x55\x1e\x85\x49\x18\xae\xd7\x60\xcf\xfe\x63\x6c\x43\xd9\x54\xb9\x02\x06\x12\x5d\x39\x31\xcd\x1b\x61\x68\x9c\xb4\x81\x69\x90\x3b\xa1\x79\x8d\x69\xf8\xc8\xe4\xcc\xc0\x29\x14\x3b\x91\xc5\x09\x1c\x0f\xf1\xa6\x37\x56\xab\x0b\x03\xfa\xdb\x80\xfb\x6e\x71\xd9\x11\xd6\x27\x50\xb3\x07\x8c\xef\x7e\x4c\xba\xe6\x7c\x05\x5d\x07\x15\x0a\x8f\x92\xa4\x9f\x11\xc6\x57\xfb\x48\x9b\x2c\xa8\x3b\x43\x14\x87\xbe\xff\x01\xbe\x73\x73\xd7\x85\x41\x10\x98\x87\x9b\x16\xb3\x13\x98\xdd\x99\x23\xba\x0f\x6e\xd9\x7d\x85\x27\xb0\xe4\x3b\xa5\xf3\x15\x89\x9c\x37\xd5\xae\x16\x6a\x8f\x90\xbb\xb1\x62\x9b\x8b\x13\x2f\x82\xcf\x86\x88\xc9\x4d\x70\xfb\xd4\xe2\x09\x10\x3d\xa9\xb5\xb3\xb9\x48\xcd\xa1\x29\x3e\xa5\xbf\xb2\xda\x58\xb4\x96\x9c\xc7\x3d\x0e\x47\x4d\x52\x62\x42\x8f\x3a\xf6\x97\xfd\x69\x7d\x45\x56\xd8\x59\x8e\xe8\x86\xa2\x22\x3a\xda\x3b\xa5\x25\x17\x5b\x8f\x92\x45\xc8\x1e\x0d\x05\x51\x20\xac\x04\x91\x00\x7b\xfe\xed\x8d\xb6\xf0\x43\x3d\x81\x6e\x89\x43\xb1\x07\x04\x38\x98\xff\xcc\xa2\xcb\xde\x7b\x37\x07\x14\xfa\xd9\x1b\x7b\xb8\x0b\x78\x97\xe8\x52\xbd\xcc\xb7\xc3\xad\xab\xb7\xab\x9d\xd2\x67\x79\x7e\x19\x93\x47\x42\x17\xe7\xe8\x06\x13\xfd\x46\xdd\x63\xff\x1b\x56\x5e\x05\x5a\xd5\x6f\x58\x51\xee\x13\xed\x1b\xf1\x88\x52\xb9\x6a\xc4\x74\xa3\xdc\xc1\x24\xf1\x52\xb5\x5a\x05\xba\x7d\x56\x19\xb3\xfa\xe5\x85\x11\xbc\xfa\x78\x05\x7d\xff\x82\x95\xeb\xff\x7a\x26\xba\x0e\xb0\xa2\x08\xee\x7e\xd8\x82\xe9\x5e\xf2\x6e\xdd\x78\xba\x40\xda\x84\xbf\x8b\xe4\x13\xcf\xf9\x90\x9d\x79\x5e\x54\x6f\xb0\xaf\x64\x07\xa4\xa9\x4c\x66\x37\x49\x18\x3c\xa3\x78\x78\x96\xa8\x77\x52\x00\xe1\x1d\xf6\xb1\xed\x87\xe3\x54\x38\xcb\xcd\x24\xfc\x25\x59\xab\x68\xb6\xb1\x3c\xbf\x1e\xee\xa0\x46\x5d\x36\x79\x6a\x14\xcc\x8c\xdd\xb5\x39\xd3\xb8\x72\xbf\xdf\x37\x02\x81\x89\x1c\x7e\xee\x50\x3e\xc1\xfd\x8e\x57\x39\x4a\x05\xbc\x6e\x2b\xac\xcd\x94\xa6\xa9\xc8\x85\x46\x69\xfa\x73\x1a\x6a\x43\xf1\xc2\xf3\x78\x6d\x7a\xa7\xef\x3c\xa6\x1e\xab\xa8\xc7\xa6\x37\x58\xd1\xb0\x4d\x92\xd0\xce\xcc\x43\x4d\xd1\x80\xe4\xa2\x71\x15\xfc\x7f\x13\xa1\x03\xcc\xde\x4b\xcc\x90\x3f\x5a\x81\xf1\x79\xd4\x1a\xa4\xea\x9d\x9b\x0d\xd6\xcc\x95\xfb\x73\x66\xa9\xe0\x95\xb6\x76\x5a\xc9\x85\xb6\xbd\xc1\x1c\x0d\x52\x61\xb0\x5e\xcf\x61\x1d\x11\xb2\x90\xbf\x84\x48\x1a\x06\x06\x03\x88\x67\x01\xf7\x3d\x1c\xfb\x19\xf6\x7d\x32\xb3\x1e\x1b\x73\xb0\x1f\x3c\x83\x71\xb0\xb0\x96\x8e\xee\x15\x9c\x02\x6b\x5b\x14\xf9\xd2\xa3\x27\xb3\xa2\x70\x93\x30\x70\x89\xd9\x5c\xc1\x16\x99\x99\xaa\xee\x60\xcc\xd1\x02\xa8\x1b\x63\xba\x7a\x02\x0b\x97\x82\xc6\xae\x52\xf3\x4c\x86\x22\x7a\x7d\xe6\xd6\x9b\x19\xc5\x1e\x17\x7d\x4f\x89\xba\xc2\x7f\x37\xbb\xb1\xef\xac\x6f\xb3\x1f\x73\xf9\x4b\x24\xd5\x36\x84\xb1\x64\xde\xcc\x4b\xbd\x97\x89\xfa\x0d\xd8\x0b\xa0\xdd\x28\xfd\x5e\xa2\xc4\xb7\x30\xe0\x05\xfd\x8c\x82\x7d\x79\xbd\x1d\xf5\x7a\x42\x79\xae\xd2\xca\xe6\x91\x9b\x37\x97\xc1\x16\x05\x4a\x9e\xb9\x00\xb9\xd8\x42\xc6\x5a\x76\xcf\x2b\xae\x9f\xbc\x7d\x0c\x8a\x46\x2e\xea\x26\x0d\x03\xea\x2d\x73\xd3\x4a\xcb\x5d\xa6\x29\xa8\x39\x7b\x63\x28\x16\x28\x03\x0b\x47\x4b\x33\x01\x38\x91\x3d\x80\x64\x5b\x9c\x35\x3d\x22\x53\x2c\xd2\x4f\xac\xbd\xb8\x75\x34\x5c\x5b\x5e\x8b\xf4\xf7\x6d\x8d\x04\x03\x5e\x00\x4a\x6a\x25\xde\xb6\x99\x5e\x3e\xb2\xea\x3a\xf6\x4f\x16\xeb\x1e\xcd\x83\x15\xb4\x2b\x50\xc9\xbf\xc9\xc2\x3f\x4e\x41\xf0\xca\x1a\x0d\x54\x6a\x46\xb5\x94\x8d\x8c\x51\xca\x84\xb6\x02\xb3\x14\xb8\x3a\x32\x66\x08\x3c\xdb\xe3\x86\x55\x8c\x7e\xdc\xd0\x98\x1b\x5b\x1d\xa7\x3e\x3d\x76\xba\xb8\x65\x2a\x63\x95\x55\x4f\x20\xba\xa6\x2f\x9a\x11\xd7\xcd\xc5\x1e\x64\x47\x6f\x44\xfd\x02\x65\x9e\xbb\x6d\xe8\x37\x08\x6f\x2e\x46\x8c\xa7\xb0\xcc\xad\x85\xdb\xb1\x60\x57\xb4\xf8\x55\x8b\x63\x32\x81\xf1\xe2\x9e\x17\xcc\xa1\x2a\xf6\xe3\xf4\x06\xa0\x02\xb7\x84\x14\xe9\x46\xdd\x72\x1a\x16\x93\xf2\x29\x44\xe6\x8c\x44\x87\xcd\x63\x10\xfe\xf4\xa4\x69\xd4\xcd\xa4\xe9\x70\x14\x1f\x16\xc0\x81\x0c\xbb\x2d\xde\xd0\x1b\x41\x29\x19\x02\xde\x48\x8f\xb5\xe1\xc6\xda\xc8\xd4\x61\xaa\xf6\xf9\x3d\x40\xde\xeb\xd8\x2b\x96\xd4\xd9\x0d\x77\xfc\x24\x75\x1b\xf8\xcb\x6b\x2c\x19\x31\x61\x8f\x14\x45\xe4\xf6\x0b\x53\x91\x59\xb0\xe6\xf1\x5a\x18\x47\x1d\x0f\x38\xe6\x81\xa4\x1b\xc8\x4a\xcc\x1e\x0c\x4b\xb6\x5d\x94\xcc\xf6\xe4\x7c\x8b\x30\x5b\x91\x0f\xa1\xe6\xb9\x89\x17\x98\x58\xd0\xbe\x30\x65\x32\x89\x17\x5b\xb7\x83\xc1\x4f\xee\xf7\xb9\x45\xdf\xb9\x2e\xa3\xbf\x23\x45\xf8\xc5\x75\x69\x7a\x3a\x7f\x44\x01\x59\x23\x72\x6e\xa6\x87\x82\xb8\xd1\x25\xca\xc9\xa8\x4a\x5e\x8b\x86\x51\x51\x90\xa6\xd3\x40\x4c\x9f\xaf\xc3\x87\x20\x33\xc9\x2e\x61\x5b\x4d\x9f\x22\xdf\x25\x6b\x3f\x9b\xe6\x7c\xa0\x43\x07\x66\xf6\xfc\xb1\x82\x96\xf6\x46\xaa\x2f\x1b\x96\xfb\xb8\x69\x63\x95\xd8\x2d\x9e\xda\x6c\xe2\x58\x71\x05\xe9\xea\xd3\xab\xd4\xe9\xf1\xcf\x00\x00\x00\xff\xff\x4e\xf0\xc6\xe3\xee\x12\x00\x00") +var _templateDialectSqlEntqlTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x57\x5f\x4f\xdc\x48\x12\x7f\xb6\x3f\x45\x9d\x85\x22\x1b\x4d\x3c\xb9\xbc\x1d\x27\x1e\x08\x90\xcb\xe8\x96\x88\x0d\x64\xf3\x80\xa2\x55\x63\x97\xc7\x2d\xec\xb6\xd3\xdd\x26\x42\x96\xbf\xfb\xaa\xab\xdb\x7f\x99\x99\x80\x56\x1b\x29\x60\xba\xeb\xef\xef\x57\xae\x2a\xb7\xed\xfa\xd8\x3f\xaf\xea\x27\xc9\xb7\xb9\x86\xf7\xef\xfe\xfd\x9f\xb7\xb5\x44\x85\x42\xc3\x47\x96\xe0\x7d\x55\x3d\xc0\x46\x24\x31\x9c\x15\x05\x90\x90\x02\x73\x2f\x1f\x31\x8d\xfd\xdb\x9c\x2b\x50\x55\x23\x13\x84\xa4\x4a\x11\xb8\x82\x82\x27\x28\x14\xa6\xd0\x88\x14\x25\xe8\x1c\xe1\xac\x66\x49\x8e\xf0\x3e\x7e\xd7\xdf\x42\x56\x35\x22\xf5\xb9\xa0\xfb\xdf\x36\xe7\x97\x9f\x6f\x2e\x21\xe3\x05\x82\x3b\x93\x55\xa5\x21\xe5\x12\x13\x5d\xc9\x27\xa8\x32\xd0\x13\x67\x5a\x22\xc6\xfe\xf1\xba\xeb\x7c\xbf\x6d\x21\xc5\x8c\x0b\x84\x20\xe5\xac\xc0\x44\xaf\xd5\x8f\x62\x8d\x42\xff\x28\x02\x70\x12\x47\xf5\xc3\x16\x4e\x4e\xe1\x9e\x29\x84\xa3\xf8\xbc\x12\x19\xdf\xc6\xd7\x2c\x79\x60\x5b\x34\x42\x6d\x0b\x1a\xcb\xba\x60\x1a\x21\xc8\x91\xa5\x28\x03\x38\x22\x75\x5e\xd6\x95\xd4\x10\xfa\x5e\x60\x2c\x3d\x57\x5e\xd7\x12\x53\x9e\x30\x8d\x81\xef\xb5\xed\x5b\x90\x4c\x6c\x11\x8e\x84\xf1\x78\x14\x7f\xae\x52\x54\xc6\x92\xb7\xd7\x80\x39\x16\x93\x03\x67\x07\x45\x4a\x11\x78\xc1\x96\xeb\xbc\xb9\x8f\x93\xaa\x5c\x67\x8e\x17\x93\xe1\x7a\x92\x71\xf0\x32\x31\xf3\x7f\x2b\x59\x9d\x1f\x92\xb7\xe0\x1d\x10\x50\x49\x8e\x25\x5b\x67\x1c\x8b\x34\xf0\x23\xdf\x5f\xaf\xc1\x9e\xfd\xcf\xd8\x86\xbc\x2a\x52\x05\x0c\x24\xba\x72\x62\x9a\x57\xc2\xd0\x38\x6a\x03\xd3\x20\x1b\xa1\x79\x89\xb1\xff\xc8\xe4\xcc\xc0\x29\x64\x8d\x48\xc2\x08\x8e\xfb\x78\xe3\x1b\xab\xd5\xfa\x1e\xfd\x6d\xc0\x7d\xb3\xb8\x6c\x09\xeb\x13\x28\xd9\x03\x86\x77\xdf\x47\x5d\x73\xbe\x82\xb6\x85\x02\xc5\x84\x92\xa8\x9b\x11\xc6\x57\xbb\x48\x1b\x2d\xa8\x3b\x43\x14\x87\xae\xfb\x0e\x53\xe7\xe6\xae\xf5\x3d\xcf\x33\x0f\x37\x35\x26\x27\x30\xbb\x33\x47\x74\xef\xdd\xb2\xfb\x02\x4f\x60\xc9\x77\x4c\xe7\x2b\x12\x39\xaf\x8a\xa6\x14\x6a\x87\x90\xbb\xb1\x62\x9b\x8b\x93\x49\x04\x1f\x0d\x11\xa3\x1b\xef\xf6\xa9\xc6\x13\x20\x7a\x62\x6b\x67\x73\x11\x9b\x43\x53\x7c\x4a\x7f\x66\xa5\xb1\x68\x2d\x39\x8f\x3b\x1c\x0e\x9a\xa4\xc4\x84\x1e\x74\xec\x2f\xfb\xd3\xfa\x0a\xac\xb0\xb3\x1c\xd0\x0d\x45\x45\x74\xd4\x77\x4a\x4b\x2e\xb6\x13\x4a\x16\x21\x4f\x68\xc8\x88\x02\x61\x25\x88\x04\xd8\xf1\x6f\x67\xb4\xd9\x34\xd4\x13\x68\x97\x38\x64\x3b\x40\x80\x83\xf9\xcf\x2c\xba\xec\x27\xef\x66\x8f\x42\x37\x7b\x63\x0f\x77\x81\xc9\x25\xba\x54\x2f\xd3\x6d\x7f\xeb\xea\xed\xaa\x51\xfa\x2c\x4d\x2f\x43\xf2\x48\xe8\xe2\x1c\x5d\x6f\xa4\xdf\xa8\x4f\xd8\xff\x82\xc5\xa4\x02\xad\xea\x17\x2c\x28\xf7\x91\xf6\x8d\x78\x44\xa9\x5c\x35\x62\xbc\x51\xee\x60\x94\xd8\x57\xad\x56\x81\x6e\x9f\x55\xc6\xac\x7e\x79\x66\x04\xaf\xde\x5f\x41\xd7\xed\xb1\x72\xfd\xff\x89\x89\xb6\x05\x2c\x28\x82\xbb\xef\xb6\x60\xda\x7d\xde\xad\x9b\x89\x2e\x90\x36\xe1\xef\x22\xf9\xc0\x53\xde\x67\x67\x9e\x17\xd5\xeb\xed\x2a\xd9\x1e\x69\x2a\x93\xd9\x4d\xe4\x7b\xcf\x28\xee\x9f\x25\xea\x46\x0a\x20\xbc\xfd\x2e\xb4\xfd\x70\x98\x0a\x67\xa9\x99\x84\x3f\x25\xab\x15\xcd\x36\x96\xa6\xd7\xfd\x1d\x94\xa8\xf3\x2a\x8d\x8d\x82\x99\xb1\x4d\x9d\x32\x8d\x2b\xf7\xfb\x6d\x25\x10\x98\x48\xe1\x47\x83\xf2\x09\xee\x1b\x5e\xa4\x28\x15\xf0\xb2\x2e\xb0\x34\x53\x9a\xa6\x22\x17\x1a\xa5\xe9\xcf\xb1\xaf\x0d\xc5\x0b\xcf\xc3\xb5\xe9\x9d\x53\xe7\x21\xf5\x58\x45\x3d\x36\xbe\xc1\x82\x86\x6d\x14\xf9\x76\x66\x1e\x6a\x8a\x06\x24\x17\x8d\xab\xe0\xdf\x4d\x84\x0e\x30\x7b\x2f\x31\x41\xfe\x68\x05\x86\xe7\x41\xab\x97\x2a\x1b\x37\x1b\xac\x99\x2b\xf7\xe7\xcc\x52\xc6\x0b\x6d\xed\xd4\x92\x0b\x6d\x7b\x83\x39\xea\xa5\x7c\x6f\xbd\x9e\xc3\x3a\x20\x64\x21\xdf\x87\x48\xec\x7b\x06\x03\x08\x67\x01\x77\x1d\x1c\x4f\x33\xec\xba\x68\x66\x3d\x34\xe6\x60\x37\x78\x06\x63\x6f\x61\x2d\x1e\xdc\x2b\x38\x05\x56\xd7\x28\xd2\xa5\xc7\x89\xcc\x8a\xc2\x8d\x7c\xcf\x25\x66\x73\x05\x5b\x64\x66\xaa\xba\x83\x21\x47\x0b\xa0\xae\x8c\xe9\xe2\x09\x2c\x5c\x0a\x2a\xbb\x4a\xcd\x33\xe9\x8b\xe8\xe5\x99\x5b\x6f\x66\x14\x4f\xb8\xe8\x3a\x4a\xd4\x15\xfe\x9b\xd9\x8d\x7d\x67\xa7\x36\xbb\x21\x97\xbf\x45\x52\x69\x43\x18\x4a\xe6\xd5\xbc\x94\x3b\x99\x28\x5f\x81\xbd\x00\xda\x8d\xe2\x6f\x39\x4a\x7c\x0d\x03\x93\xa0\x9f\x51\xb0\x2b\xaf\xd7\xa3\x5e\x8e\x28\xcf\x55\x6a\x59\x3d\x72\xf3\xe6\x32\xd8\xa2\x40\xc9\x13\x17\x20\x17\x5b\x48\x58\xcd\xee\x79\xc1\xf5\xd3\x64\x1f\x83\xac\x92\x8b\xba\x89\x7d\x8f\x7a\xcb\xdc\xb4\xd2\xb2\x49\x34\x05\x35\x67\x6f\x08\xc5\x02\x65\x60\xe1\x68\x69\x26\x00\x47\xb2\x7b\x90\x6c\x8b\xb3\xa6\x07\x64\xb2\x45\xfa\x91\xb5\x17\xd6\x8e\x86\x6b\xcb\x6b\x16\xff\xba\xad\x91\xa0\xc7\x33\x40\x49\xad\x64\xb2\x6d\xc6\x97\x8f\xac\xb8\x0e\xa7\x27\x8b\x75\x8f\xe6\xc1\x0a\xea\x15\xa8\xe8\xbf\x64\xe1\x5f\xa7\x20\x78\x61\x8d\x7a\x2a\x36\xa3\x5a\xca\x4a\x86\x28\x65\x44\x5b\x81\x59\x0a\x5c\x1d\x19\x33\x04\x9e\xed\x71\xfd\x2a\x46\x3f\x6e\x68\xcc\x0d\xad\x8e\x53\x9f\x1e\x3a\x5d\x58\x33\x95\xb0\xc2\xaa\x47\x10\x5c\xd3\x17\xcd\x80\xeb\xe6\x62\x07\xb2\x83\x37\xa2\x7e\x81\x32\x4f\xdd\x36\xf4\x0b\x84\x37\x17\x03\xc6\x63\x58\xe6\xd6\xc2\xed\x58\xb0\x2b\x5a\xf8\xa2\xc5\x31\x1a\xc1\xd8\xbb\xe7\x79\x73\xa8\xb2\xdd\x38\xbd\x02\x28\xcf\x2d\x21\x59\xbc\x51\xb7\x9c\x86\xc5\xa8\x7c\x0a\x81\x39\x23\xd1\x7e\xf3\xe8\x85\x3f\x3c\x69\x1a\x75\x33\x69\x3a\xdc\x29\xfe\xf5\xeb\xe6\x62\x29\xfd\x07\x2b\x9a\xd1\x78\xbf\x2e\xf6\xd4\xd9\xdd\xf2\x86\xde\x1f\x02\xc0\xd0\xf5\x4a\x32\xad\x0d\x37\x04\x07\x5e\x0f\x13\xbb\xcb\xef\x01\xaa\x5f\xc6\x75\xb6\x24\xda\xee\xc3\xc3\x07\xac\xdb\xd7\xf7\x2f\xbd\x64\xc4\x84\x3d\x10\x1a\x90\xdb\x4f\x4c\x05\x66\x1d\x9b\xc7\x6b\x61\x1c\x74\x26\xc0\xb1\x09\x48\xba\x82\x24\xc7\xe4\xc1\x90\x64\x9b\x4b\xce\x6c\x07\x4f\xb7\x08\xb3\x85\xfa\x10\x6a\x13\x37\xe1\x02\x13\x0b\xda\x27\xa6\x4c\x26\xe1\x62\x47\x77\x30\x4c\x93\xfb\x75\x6e\xc1\x37\xae\xf3\xe0\x9f\x48\x11\x7e\x72\x9d\x9b\x09\xc0\x1f\x51\x40\x52\x89\x94\x9b\x59\xa3\x20\xac\x74\x8e\x72\x34\xaa\xa2\x97\xa2\x61\x54\x14\xc4\xf1\x38\x3e\xe3\xe7\xcb\xf3\x21\xc8\x4c\xb2\x4b\xd8\x56\xe3\x87\xcb\x37\xc9\xea\x8f\xa6\x95\x1f\xe8\xe7\x9e\x99\x54\x7f\xae\xa0\xa6\x2d\x93\xea\xcb\x86\xe5\x3e\x85\xea\x50\x45\x76\xe7\xa7\xa6\x1c\x39\x56\x5c\x41\xba\xfa\x9c\x54\xea\xf8\xf8\x57\x00\x00\x00\xff\xff\x7f\x6d\xc6\xd7\x1c\x13\x00\x00") func templateDialectSqlEntqlTmplBytes() ([]byte, error) { return bindataRead( @@ -705,7 +705,7 @@ func templateDialectSqlEntqlTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/dialect/sql/entql.tmpl", size: 4846, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/dialect/sql/entql.tmpl", size: 4892, 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/entql.tmpl b/entc/gen/template/dialect/sql/entql.tmpl index 32e022227..40a93da75 100644 --- a/entc/gen/template/dialect/sql/entql.tmpl +++ b/entc/gen/template/dialect/sql/entql.tmpl @@ -117,7 +117,7 @@ type predicateAdder interface { {{ range $f := $n.Fields }} {{ $type := $f.Type.Type.String }} {{ $iface := print (pascal $type) "P" }} - {{ if $f.IsTime }}{{ $iface = "TimeP" }}{{ else if $f.IsBytes }}{{ $iface = "BytesP" }}{{ end }} + {{ if $f.IsTime }}{{ $iface = "TimeP" }}{{ else if $f.IsBytes }}{{ $iface = "BytesP" }}{{ else if $f.IsUUID }}{{ $iface = "ValueP" }}{{ end }} // Where{{ $f.StructField }} applies the entql {{ $type }} predicate on the {{ $f.Name }} field. func (f *{{ $filter }}) Where{{ $f.StructField }}(p entql.{{ $iface }}) { f.Where(p.Field({{ $n.Package }}.{{ $f.Constant }})) diff --git a/entc/integration/ent/entql.go b/entc/integration/ent/entql.go index 7eaad0c6d..583167a64 100644 --- a/entc/integration/ent/entql.go +++ b/entc/integration/ent/entql.go @@ -122,6 +122,7 @@ var schemaGraph = func() *sqlgraph.Schema { fieldtype.FieldNullFloat: {Type: field.TypeFloat64, Column: fieldtype.FieldNullFloat}, fieldtype.FieldRole: {Type: field.TypeEnum, Column: fieldtype.FieldRole}, fieldtype.FieldMAC: {Type: field.TypeString, Column: fieldtype.FieldMAC}, + fieldtype.FieldUUID: {Type: field.TypeUUID, Column: fieldtype.FieldUUID}, }, } graph.Nodes[3] = &sqlgraph.Node{ @@ -241,6 +242,7 @@ var schemaGraph = func() *sqlgraph.Schema { Type: "Pet", Fields: map[string]*sqlgraph.FieldSpec{ pet.FieldName: {Type: field.TypeString, Column: pet.FieldName}, + pet.FieldUUID: {Type: field.TypeUUID, Column: pet.FieldUUID}, }, } graph.Nodes[11] = &sqlgraph.Node{ @@ -1034,6 +1036,11 @@ func (f *FieldTypeFilter) WhereMAC(p entql.StringP) { f.Where(p.Field(fieldtype.FieldMAC)) } +// WhereUUID applies the entql [16]byte predicate on the uuid field. +func (f *FieldTypeFilter) WhereUUID(p entql.ValueP) { + f.Where(p.Field(fieldtype.FieldUUID)) +} + // addPredicate implements the predicateAdder interface. func (fq *FileQuery) addPredicate(pred func(s *sql.Selector)) { fq.predicates = append(fq.predicates, pred) @@ -1585,6 +1592,11 @@ func (f *PetFilter) WhereName(p entql.StringP) { f.Where(p.Field(pet.FieldName)) } +// WhereUUID applies the entql [16]byte predicate on the uuid field. +func (f *PetFilter) WhereUUID(p entql.ValueP) { + f.Where(p.Field(pet.FieldUUID)) +} + // WhereHasTeam applies a predicate to check if query has an edge team. func (f *PetFilter) WhereHasTeam() { f.Where(entql.HasEdge("team")) diff --git a/entc/integration/ent/fieldtype.go b/entc/integration/ent/fieldtype.go index 4093597a3..2eed851a0 100644 --- a/entc/integration/ent/fieldtype.go +++ b/entc/integration/ent/fieldtype.go @@ -17,6 +17,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/fieldtype" "github.com/facebook/ent/entc/integration/ent/role" "github.com/facebook/ent/entc/integration/ent/schema" + "github.com/google/uuid" ) // FieldType is the model entity for the FieldType schema. @@ -115,7 +116,9 @@ type FieldType struct { // Role holds the value of the "role" field. Role role.Role `json:"role,omitempty"` // MAC holds the value of the "mac" field. - MAC schema.MAC `json:"mac,omitempty"` + MAC schema.MAC `json:"mac,omitempty"` + // UUID holds the value of the "uuid" field. + UUID uuid.UUID `json:"uuid,omitempty"` file_field *int } @@ -169,6 +172,7 @@ func (*FieldType) scanValues() []interface{} { &sql.NullFloat64{}, // null_float &sql.NullString{}, // role &schema.MAC{}, // mac + &uuid.UUID{}, // uuid } } @@ -428,7 +432,12 @@ func (ft *FieldType) assignValues(values ...interface{}) error { } else if value != nil { ft.MAC = *value } - values = values[46:] + if value, ok := values[46].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field uuid", values[46]) + } else if value != nil { + ft.UUID = *value + } + values = values[47:] if len(values) == len(fieldtype.ForeignKeys) { if value, ok := values[0].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field file_field", value) @@ -573,6 +582,8 @@ func (ft *FieldType) String() string { builder.WriteString(fmt.Sprintf("%v", ft.Role)) builder.WriteString(", mac=") builder.WriteString(fmt.Sprintf("%v", ft.MAC)) + builder.WriteString(", uuid=") + builder.WriteString(fmt.Sprintf("%v", ft.UUID)) builder.WriteByte(')') return builder.String() } diff --git a/entc/integration/ent/fieldtype/fieldtype.go b/entc/integration/ent/fieldtype/fieldtype.go index 8a3ea3448..e8db88a6c 100644 --- a/entc/integration/ent/fieldtype/fieldtype.go +++ b/entc/integration/ent/fieldtype/fieldtype.go @@ -109,6 +109,8 @@ const ( FieldRole = "role" // FieldMAC holds the string denoting the mac field in the database. FieldMAC = "mac" + // FieldUUID holds the string denoting the uuid field in the database. + FieldUUID = "uuid" // Table holds the table name of the fieldtype in the database. Table = "field_types" @@ -163,6 +165,7 @@ var Columns = []string{ FieldNullFloat, FieldRole, FieldMAC, + FieldUUID, } // ForeignKeys holds the SQL foreign-keys that are owned by the FieldType type. diff --git a/entc/integration/ent/fieldtype/where.go b/entc/integration/ent/fieldtype/where.go index 98d2598ef..156a6c94c 100644 --- a/entc/integration/ent/fieldtype/where.go +++ b/entc/integration/ent/fieldtype/where.go @@ -15,6 +15,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/predicate" "github.com/facebook/ent/entc/integration/ent/role" "github.com/facebook/ent/entc/integration/ent/schema" + "github.com/google/uuid" ) // ID filters vertices based on their identifier. @@ -411,6 +412,13 @@ func MAC(v schema.MAC) predicate.FieldType { }) } +// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ. +func UUID(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUUID), v)) + }) +} + // IntEQ applies the EQ predicate on the "int" field. func IntEQ(v int) predicate.FieldType { return predicate.FieldType(func(s *sql.Selector) { @@ -4445,6 +4453,96 @@ func MACContainsFold(v schema.MAC) predicate.FieldType { }) } +// UUIDEQ applies the EQ predicate on the "uuid" field. +func UUIDEQ(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUUID), v)) + }) +} + +// UUIDNEQ applies the NEQ predicate on the "uuid" field. +func UUIDNEQ(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldUUID), v)) + }) +} + +// UUIDIn applies the In predicate on the "uuid" field. +func UUIDIn(vs ...uuid.UUID) predicate.FieldType { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.FieldType(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(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldUUID), v...)) + }) +} + +// UUIDNotIn applies the NotIn predicate on the "uuid" field. +func UUIDNotIn(vs ...uuid.UUID) predicate.FieldType { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.FieldType(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(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldUUID), v...)) + }) +} + +// UUIDGT applies the GT predicate on the "uuid" field. +func UUIDGT(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldUUID), v)) + }) +} + +// UUIDGTE applies the GTE predicate on the "uuid" field. +func UUIDGTE(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldUUID), v)) + }) +} + +// UUIDLT applies the LT predicate on the "uuid" field. +func UUIDLT(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldUUID), v)) + }) +} + +// UUIDLTE applies the LTE predicate on the "uuid" field. +func UUIDLTE(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldUUID), v)) + }) +} + +// UUIDIsNil applies the IsNil predicate on the "uuid" field. +func UUIDIsNil() predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldUUID))) + }) +} + +// UUIDNotNil applies the NotNil predicate on the "uuid" field. +func UUIDNotNil() predicate.FieldType { + return predicate.FieldType(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldUUID))) + }) +} + // And groups list of predicates with the AND operator between them. func And(predicates ...predicate.FieldType) predicate.FieldType { return predicate.FieldType(func(s *sql.Selector) { diff --git a/entc/integration/ent/fieldtype_create.go b/entc/integration/ent/fieldtype_create.go index fd355437e..461010911 100644 --- a/entc/integration/ent/fieldtype_create.go +++ b/entc/integration/ent/fieldtype_create.go @@ -20,6 +20,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/role" "github.com/facebook/ent/entc/integration/ent/schema" "github.com/facebook/ent/schema/field" + "github.com/google/uuid" ) // FieldTypeCreate is the builder for creating a FieldType entity. @@ -553,6 +554,12 @@ func (ftc *FieldTypeCreate) SetMAC(s schema.MAC) *FieldTypeCreate { return ftc } +// SetUUID sets the uuid field. +func (ftc *FieldTypeCreate) SetUUID(u uuid.UUID) *FieldTypeCreate { + ftc.mutation.SetUUID(u) + return ftc +} + // Mutation returns the FieldTypeMutation object of the builder. func (ftc *FieldTypeCreate) Mutation() *FieldTypeMutation { return ftc.mutation @@ -1056,6 +1063,14 @@ func (ftc *FieldTypeCreate) createSpec() (*FieldType, *sqlgraph.CreateSpec) { }) _node.MAC = value } + if value, ok := ftc.mutation.UUID(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: fieldtype.FieldUUID, + }) + _node.UUID = value + } return _node, _spec } diff --git a/entc/integration/ent/fieldtype_update.go b/entc/integration/ent/fieldtype_update.go index d65548b41..a780ac68e 100644 --- a/entc/integration/ent/fieldtype_update.go +++ b/entc/integration/ent/fieldtype_update.go @@ -20,6 +20,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/role" "github.com/facebook/ent/entc/integration/ent/schema" "github.com/facebook/ent/schema/field" + "github.com/google/uuid" ) // FieldTypeUpdate is the builder for updating FieldType entities. @@ -1004,6 +1005,18 @@ func (ftu *FieldTypeUpdate) ClearMAC() *FieldTypeUpdate { return ftu } +// SetUUID sets the uuid field. +func (ftu *FieldTypeUpdate) SetUUID(u uuid.UUID) *FieldTypeUpdate { + ftu.mutation.SetUUID(u) + return ftu +} + +// ClearUUID clears the value of uuid. +func (ftu *FieldTypeUpdate) ClearUUID() *FieldTypeUpdate { + ftu.mutation.ClearUUID() + return ftu +} + // Mutation returns the FieldTypeMutation object of the builder. func (ftu *FieldTypeUpdate) Mutation() *FieldTypeMutation { return ftu.mutation @@ -1884,6 +1897,19 @@ func (ftu *FieldTypeUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: fieldtype.FieldMAC, }) } + if value, ok := ftu.mutation.UUID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: fieldtype.FieldUUID, + }) + } + if ftu.mutation.UUIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: fieldtype.FieldUUID, + }) + } if n, err = sqlgraph.UpdateNodes(ctx, ftu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{fieldtype.Label} @@ -2871,6 +2897,18 @@ func (ftuo *FieldTypeUpdateOne) ClearMAC() *FieldTypeUpdateOne { return ftuo } +// SetUUID sets the uuid field. +func (ftuo *FieldTypeUpdateOne) SetUUID(u uuid.UUID) *FieldTypeUpdateOne { + ftuo.mutation.SetUUID(u) + return ftuo +} + +// ClearUUID clears the value of uuid. +func (ftuo *FieldTypeUpdateOne) ClearUUID() *FieldTypeUpdateOne { + ftuo.mutation.ClearUUID() + return ftuo +} + // Mutation returns the FieldTypeMutation object of the builder. func (ftuo *FieldTypeUpdateOne) Mutation() *FieldTypeMutation { return ftuo.mutation @@ -3749,6 +3787,19 @@ func (ftuo *FieldTypeUpdateOne) sqlSave(ctx context.Context) (_node *FieldType, Column: fieldtype.FieldMAC, }) } + if value, ok := ftuo.mutation.UUID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: fieldtype.FieldUUID, + }) + } + if ftuo.mutation.UUIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: fieldtype.FieldUUID, + }) + } _node = &FieldType{config: ftuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues() diff --git a/entc/integration/ent/migrate/schema.go b/entc/integration/ent/migrate/schema.go index 72997316e..2345b2455 100644 --- a/entc/integration/ent/migrate/schema.go +++ b/entc/integration/ent/migrate/schema.go @@ -99,6 +99,7 @@ var ( {Name: "null_float", Type: field.TypeFloat64, Nullable: true}, {Name: "role", Type: field.TypeEnum, Enums: []string{"ADMIN", "OWNER", "USER", "READ", "WRITE"}, Default: "READ"}, {Name: "mac", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "macaddr"}}, + {Name: "uuid", Type: field.TypeUUID, Nullable: true}, {Name: "file_field", Type: field.TypeInt, Nullable: true}, } // FieldTypesTable holds the schema information for the "field_types" table. @@ -109,7 +110,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "field_types_files_field", - Columns: []*schema.Column{FieldTypesColumns[47]}, + Columns: []*schema.Column{FieldTypesColumns[48]}, RefColumns: []*schema.Column{FilesColumns[0]}, OnDelete: schema.SetNull, @@ -283,6 +284,7 @@ var ( PetsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString}, + {Name: "uuid", Type: field.TypeUUID, Nullable: true}, {Name: "user_pets", Type: field.TypeInt, Nullable: true}, {Name: "user_team", Type: field.TypeInt, Unique: true, Nullable: true}, } @@ -294,14 +296,14 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "pets_users_pets", - Columns: []*schema.Column{PetsColumns[2]}, + Columns: []*schema.Column{PetsColumns[3]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "pets_users_team", - Columns: []*schema.Column{PetsColumns[3]}, + Columns: []*schema.Column{PetsColumns[4]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, @@ -311,7 +313,7 @@ var ( { Name: "pet_name_user_pets", Unique: false, - Columns: []*schema.Column{PetsColumns[1], PetsColumns[2]}, + Columns: []*schema.Column{PetsColumns[1], PetsColumns[3]}, }, }, } diff --git a/entc/integration/ent/mutation.go b/entc/integration/ent/mutation.go index 00eeb17f7..fa5972070 100644 --- a/entc/integration/ent/mutation.go +++ b/entc/integration/ent/mutation.go @@ -30,6 +30,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/spec" "github.com/facebook/ent/entc/integration/ent/task" "github.com/facebook/ent/entc/integration/ent/user" + "github.com/google/uuid" "github.com/facebook/ent" ) @@ -1302,6 +1303,7 @@ type FieldTypeMutation struct { null_float *sql.NullFloat64 role *role.Role mac *schema.MAC + uuid *uuid.UUID clearedFields map[string]struct{} done bool oldValue func(context.Context) (*FieldType, error) @@ -4213,6 +4215,56 @@ func (m *FieldTypeMutation) ResetMAC() { delete(m.clearedFields, fieldtype.FieldMAC) } +// SetUUID sets the uuid field. +func (m *FieldTypeMutation) SetUUID(u uuid.UUID) { + m.uuid = &u +} + +// UUID returns the uuid value in the mutation. +func (m *FieldTypeMutation) UUID() (r uuid.UUID, exists bool) { + v := m.uuid + if v == nil { + return + } + return *v, true +} + +// OldUUID returns the old uuid value of the FieldType. +// If the FieldType object wasn't provided to the builder, the object is fetched +// from the database. +// An error is returned if the mutation operation is not UpdateOne, or database query fails. +func (m *FieldTypeMutation) OldUUID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldUUID is allowed only on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldUUID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUUID: %w", err) + } + return oldValue.UUID, nil +} + +// ClearUUID clears the value of uuid. +func (m *FieldTypeMutation) ClearUUID() { + m.uuid = nil + m.clearedFields[fieldtype.FieldUUID] = struct{}{} +} + +// UUIDCleared returns if the field uuid was cleared in this mutation. +func (m *FieldTypeMutation) UUIDCleared() bool { + _, ok := m.clearedFields[fieldtype.FieldUUID] + return ok +} + +// ResetUUID reset all changes of the "uuid" field. +func (m *FieldTypeMutation) ResetUUID() { + m.uuid = nil + delete(m.clearedFields, fieldtype.FieldUUID) +} + // Op returns the operation name. func (m *FieldTypeMutation) Op() Op { return m.op @@ -4227,7 +4279,7 @@ func (m *FieldTypeMutation) Type() string { // this mutation. Note that, in order to get all numeric // fields that were in/decremented, call AddedFields(). func (m *FieldTypeMutation) Fields() []string { - fields := make([]string, 0, 46) + fields := make([]string, 0, 47) if m.int != nil { fields = append(fields, fieldtype.FieldInt) } @@ -4366,6 +4418,9 @@ func (m *FieldTypeMutation) Fields() []string { if m.mac != nil { fields = append(fields, fieldtype.FieldMAC) } + if m.uuid != nil { + fields = append(fields, fieldtype.FieldUUID) + } return fields } @@ -4466,6 +4521,8 @@ func (m *FieldTypeMutation) Field(name string) (ent.Value, bool) { return m.Role() case fieldtype.FieldMAC: return m.MAC() + case fieldtype.FieldUUID: + return m.UUID() } return nil, false } @@ -4567,6 +4624,8 @@ func (m *FieldTypeMutation) OldField(ctx context.Context, name string) (ent.Valu return m.OldRole(ctx) case fieldtype.FieldMAC: return m.OldMAC(ctx) + case fieldtype.FieldUUID: + return m.OldUUID(ctx) } return nil, fmt.Errorf("unknown FieldType field %s", name) } @@ -4898,6 +4957,13 @@ func (m *FieldTypeMutation) SetField(name string, value ent.Value) error { } m.SetMAC(v) return nil + case fieldtype.FieldUUID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUUID(v) + return nil } return fmt.Errorf("unknown FieldType field %s", name) } @@ -5399,6 +5465,9 @@ func (m *FieldTypeMutation) ClearedFields() []string { if m.FieldCleared(fieldtype.FieldMAC) { fields = append(fields, fieldtype.FieldMAC) } + if m.FieldCleared(fieldtype.FieldUUID) { + fields = append(fields, fieldtype.FieldUUID) + } return fields } @@ -5533,6 +5602,9 @@ func (m *FieldTypeMutation) ClearField(name string) error { case fieldtype.FieldMAC: m.ClearMAC() return nil + case fieldtype.FieldUUID: + m.ClearUUID() + return nil } return fmt.Errorf("unknown FieldType nullable field %s", name) } @@ -5680,6 +5752,9 @@ func (m *FieldTypeMutation) ResetField(name string) error { case fieldtype.FieldMAC: m.ResetMAC() return nil + case fieldtype.FieldUUID: + m.ResetUUID() + return nil } return fmt.Errorf("unknown FieldType field %s", name) } @@ -9387,6 +9462,7 @@ type PetMutation struct { typ string id *int name *string + uuid *uuid.UUID clearedFields map[string]struct{} team *int clearedteam bool @@ -9513,6 +9589,56 @@ func (m *PetMutation) ResetName() { m.name = nil } +// SetUUID sets the uuid field. +func (m *PetMutation) SetUUID(u uuid.UUID) { + m.uuid = &u +} + +// UUID returns the uuid value in the mutation. +func (m *PetMutation) UUID() (r uuid.UUID, exists bool) { + v := m.uuid + if v == nil { + return + } + return *v, true +} + +// OldUUID returns the old uuid value of the Pet. +// If the Pet object wasn't provided to the builder, the object is fetched +// from the database. +// An error is returned if the mutation operation is not UpdateOne, or database query fails. +func (m *PetMutation) OldUUID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldUUID is allowed only on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldUUID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUUID: %w", err) + } + return oldValue.UUID, nil +} + +// ClearUUID clears the value of uuid. +func (m *PetMutation) ClearUUID() { + m.uuid = nil + m.clearedFields[pet.FieldUUID] = struct{}{} +} + +// UUIDCleared returns if the field uuid was cleared in this mutation. +func (m *PetMutation) UUIDCleared() bool { + _, ok := m.clearedFields[pet.FieldUUID] + return ok +} + +// ResetUUID reset all changes of the "uuid" field. +func (m *PetMutation) ResetUUID() { + m.uuid = nil + delete(m.clearedFields, pet.FieldUUID) +} + // SetTeamID sets the team edge to User by id. func (m *PetMutation) SetTeamID(id int) { m.team = &id @@ -9605,10 +9731,13 @@ func (m *PetMutation) Type() string { // this mutation. Note that, in order to get all numeric // fields that were in/decremented, call AddedFields(). func (m *PetMutation) Fields() []string { - fields := make([]string, 0, 1) + fields := make([]string, 0, 2) if m.name != nil { fields = append(fields, pet.FieldName) } + if m.uuid != nil { + fields = append(fields, pet.FieldUUID) + } return fields } @@ -9619,6 +9748,8 @@ func (m *PetMutation) Field(name string) (ent.Value, bool) { switch name { case pet.FieldName: return m.Name() + case pet.FieldUUID: + return m.UUID() } return nil, false } @@ -9630,6 +9761,8 @@ func (m *PetMutation) OldField(ctx context.Context, name string) (ent.Value, err switch name { case pet.FieldName: return m.OldName(ctx) + case pet.FieldUUID: + return m.OldUUID(ctx) } return nil, fmt.Errorf("unknown Pet field %s", name) } @@ -9646,6 +9779,13 @@ func (m *PetMutation) SetField(name string, value ent.Value) error { } m.SetName(v) return nil + case pet.FieldUUID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUUID(v) + return nil } return fmt.Errorf("unknown Pet field %s", name) } @@ -9675,7 +9815,11 @@ func (m *PetMutation) AddField(name string, value ent.Value) error { // ClearedFields returns all nullable fields that were cleared // during this mutation. func (m *PetMutation) ClearedFields() []string { - return nil + var fields []string + if m.FieldCleared(pet.FieldUUID) { + fields = append(fields, pet.FieldUUID) + } + return fields } // FieldCleared returns a boolean indicates if this field was @@ -9688,6 +9832,11 @@ func (m *PetMutation) FieldCleared(name string) bool { // ClearField clears the value for the given name. It returns an // error if the field is not defined in the schema. func (m *PetMutation) ClearField(name string) error { + switch name { + case pet.FieldUUID: + m.ClearUUID() + return nil + } return fmt.Errorf("unknown Pet nullable field %s", name) } @@ -9699,6 +9848,9 @@ func (m *PetMutation) ResetField(name string) error { case pet.FieldName: m.ResetName() return nil + case pet.FieldUUID: + m.ResetUUID() + return nil } return fmt.Errorf("unknown Pet field %s", name) } diff --git a/entc/integration/ent/pet.go b/entc/integration/ent/pet.go index 247cc9879..b129b6599 100644 --- a/entc/integration/ent/pet.go +++ b/entc/integration/ent/pet.go @@ -13,6 +13,7 @@ import ( "github.com/facebook/ent/dialect/sql" "github.com/facebook/ent/entc/integration/ent/pet" "github.com/facebook/ent/entc/integration/ent/user" + "github.com/google/uuid" ) // Pet is the model entity for the Pet schema. @@ -22,6 +23,8 @@ type Pet struct { ID int `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` + // UUID holds the value of the "uuid" field. + UUID uuid.UUID `json:"uuid,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the PetQuery when eager-loading is set. Edges PetEdges `json:"edges"` @@ -73,6 +76,7 @@ func (*Pet) scanValues() []interface{} { return []interface{}{ &sql.NullInt64{}, // id &sql.NullString{}, // name + &uuid.UUID{}, // uuid } } @@ -101,7 +105,12 @@ func (pe *Pet) assignValues(values ...interface{}) error { } else if value.Valid { pe.Name = value.String } - values = values[1:] + if value, ok := values[1].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field uuid", values[1]) + } else if value != nil { + pe.UUID = *value + } + values = values[2:] if len(values) == len(pet.ForeignKeys) { if value, ok := values[0].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field user_pets", value) @@ -154,6 +163,8 @@ func (pe *Pet) String() string { builder.WriteString(fmt.Sprintf("id=%v", pe.ID)) builder.WriteString(", name=") builder.WriteString(pe.Name) + builder.WriteString(", uuid=") + builder.WriteString(fmt.Sprintf("%v", pe.UUID)) builder.WriteByte(')') return builder.String() } diff --git a/entc/integration/ent/pet/pet.go b/entc/integration/ent/pet/pet.go index 87f2f1fa3..d6b655021 100644 --- a/entc/integration/ent/pet/pet.go +++ b/entc/integration/ent/pet/pet.go @@ -13,6 +13,8 @@ const ( FieldID = "id" // FieldName holds the string denoting the name field in the database. FieldName = "name" + // FieldUUID holds the string denoting the uuid field in the database. + FieldUUID = "uuid" // EdgeTeam holds the string denoting the team edge name in mutations. EdgeTeam = "team" @@ -41,6 +43,7 @@ const ( var Columns = []string{ FieldID, FieldName, + FieldUUID, } // ForeignKeys holds the SQL foreign-keys that are owned by the Pet type. diff --git a/entc/integration/ent/pet/where.go b/entc/integration/ent/pet/where.go index 88cb59050..a7d2d654c 100644 --- a/entc/integration/ent/pet/where.go +++ b/entc/integration/ent/pet/where.go @@ -10,6 +10,7 @@ import ( "github.com/facebook/ent/dialect/sql" "github.com/facebook/ent/dialect/sql/sqlgraph" "github.com/facebook/ent/entc/integration/ent/predicate" + "github.com/google/uuid" ) // ID filters vertices based on their identifier. @@ -102,6 +103,13 @@ func Name(v string) predicate.Pet { }) } +// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ. +func UUID(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUUID), v)) + }) +} + // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Pet { return predicate.Pet(func(s *sql.Selector) { @@ -213,6 +221,96 @@ func NameContainsFold(v string) predicate.Pet { }) } +// UUIDEQ applies the EQ predicate on the "uuid" field. +func UUIDEQ(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUUID), v)) + }) +} + +// UUIDNEQ applies the NEQ predicate on the "uuid" field. +func UUIDNEQ(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldUUID), v)) + }) +} + +// UUIDIn applies the In predicate on the "uuid" field. +func UUIDIn(vs ...uuid.UUID) predicate.Pet { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Pet(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(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldUUID), v...)) + }) +} + +// UUIDNotIn applies the NotIn predicate on the "uuid" field. +func UUIDNotIn(vs ...uuid.UUID) predicate.Pet { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Pet(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(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldUUID), v...)) + }) +} + +// UUIDGT applies the GT predicate on the "uuid" field. +func UUIDGT(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldUUID), v)) + }) +} + +// UUIDGTE applies the GTE predicate on the "uuid" field. +func UUIDGTE(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldUUID), v)) + }) +} + +// UUIDLT applies the LT predicate on the "uuid" field. +func UUIDLT(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldUUID), v)) + }) +} + +// UUIDLTE applies the LTE predicate on the "uuid" field. +func UUIDLTE(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldUUID), v)) + }) +} + +// UUIDIsNil applies the IsNil predicate on the "uuid" field. +func UUIDIsNil() predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldUUID))) + }) +} + +// UUIDNotNil applies the NotNil predicate on the "uuid" field. +func UUIDNotNil() predicate.Pet { + return predicate.Pet(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldUUID))) + }) +} + // HasTeam applies the HasEdge predicate on the "team" edge. func HasTeam() predicate.Pet { return predicate.Pet(func(s *sql.Selector) { diff --git a/entc/integration/ent/pet_create.go b/entc/integration/ent/pet_create.go index 8273d672f..e50be2450 100644 --- a/entc/integration/ent/pet_create.go +++ b/entc/integration/ent/pet_create.go @@ -15,6 +15,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/pet" "github.com/facebook/ent/entc/integration/ent/user" "github.com/facebook/ent/schema/field" + "github.com/google/uuid" ) // PetCreate is the builder for creating a Pet entity. @@ -30,6 +31,12 @@ func (pc *PetCreate) SetName(s string) *PetCreate { return pc } +// SetUUID sets the uuid field. +func (pc *PetCreate) SetUUID(u uuid.UUID) *PetCreate { + pc.mutation.SetUUID(u) + return pc +} + // SetTeamID sets the team edge to User by id. func (pc *PetCreate) SetTeamID(id int) *PetCreate { pc.mutation.SetTeamID(id) @@ -157,6 +164,14 @@ func (pc *PetCreate) createSpec() (*Pet, *sqlgraph.CreateSpec) { }) _node.Name = value } + if value, ok := pc.mutation.UUID(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: pet.FieldUUID, + }) + _node.UUID = value + } if nodes := pc.mutation.TeamIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, diff --git a/entc/integration/ent/pet_update.go b/entc/integration/ent/pet_update.go index 8e31590eb..4965d9961 100644 --- a/entc/integration/ent/pet_update.go +++ b/entc/integration/ent/pet_update.go @@ -16,6 +16,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/predicate" "github.com/facebook/ent/entc/integration/ent/user" "github.com/facebook/ent/schema/field" + "github.com/google/uuid" ) // PetUpdate is the builder for updating Pet entities. @@ -37,6 +38,18 @@ func (pu *PetUpdate) SetName(s string) *PetUpdate { return pu } +// SetUUID sets the uuid field. +func (pu *PetUpdate) SetUUID(u uuid.UUID) *PetUpdate { + pu.mutation.SetUUID(u) + return pu +} + +// ClearUUID clears the value of uuid. +func (pu *PetUpdate) ClearUUID() *PetUpdate { + pu.mutation.ClearUUID() + return pu +} + // SetTeamID sets the team edge to User by id. func (pu *PetUpdate) SetTeamID(id int) *PetUpdate { pu.mutation.SetTeamID(id) @@ -168,6 +181,19 @@ func (pu *PetUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: pet.FieldName, }) } + if value, ok := pu.mutation.UUID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: pet.FieldUUID, + }) + } + if pu.mutation.UUIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: pet.FieldUUID, + }) + } if pu.mutation.TeamCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, @@ -262,6 +288,18 @@ func (puo *PetUpdateOne) SetName(s string) *PetUpdateOne { return puo } +// SetUUID sets the uuid field. +func (puo *PetUpdateOne) SetUUID(u uuid.UUID) *PetUpdateOne { + puo.mutation.SetUUID(u) + return puo +} + +// ClearUUID clears the value of uuid. +func (puo *PetUpdateOne) ClearUUID() *PetUpdateOne { + puo.mutation.ClearUUID() + return puo +} + // SetTeamID sets the team edge to User by id. func (puo *PetUpdateOne) SetTeamID(id int) *PetUpdateOne { puo.mutation.SetTeamID(id) @@ -391,6 +429,19 @@ func (puo *PetUpdateOne) sqlSave(ctx context.Context) (_node *Pet, err error) { Column: pet.FieldName, }) } + if value, ok := puo.mutation.UUID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: pet.FieldUUID, + }) + } + if puo.mutation.UUIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: pet.FieldUUID, + }) + } if puo.mutation.TeamCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2O, diff --git a/entc/integration/ent/schema/fieldtype.go b/entc/integration/ent/schema/fieldtype.go index 34ae16f7e..82b188455 100644 --- a/entc/integration/ent/schema/fieldtype.go +++ b/entc/integration/ent/schema/fieldtype.go @@ -16,6 +16,8 @@ import ( "github.com/facebook/ent/dialect/sql" "github.com/facebook/ent/entc/integration/ent/role" "github.com/facebook/ent/schema/field" + + "github.com/google/uuid" ) // FieldType holds the schema definition for the FieldType entity. @@ -140,6 +142,8 @@ func (FieldType) Fields() []ent.Field { _, err := net.ParseMAC(s) return err }), + field.UUID("uuid", uuid.UUID{}). + Optional(), } } diff --git a/entc/integration/ent/schema/pet.go b/entc/integration/ent/schema/pet.go index 76f0f0890..0aefce87a 100644 --- a/entc/integration/ent/schema/pet.go +++ b/entc/integration/ent/schema/pet.go @@ -9,6 +9,8 @@ import ( "github.com/facebook/ent/schema/edge" "github.com/facebook/ent/schema/field" "github.com/facebook/ent/schema/index" + + "github.com/google/uuid" ) // Pet holds the schema definition for the Pet entity. @@ -20,6 +22,8 @@ type Pet struct { func (Pet) Fields() []ent.Field { return []ent.Field{ field.String("name"), + field.UUID("uuid", uuid.UUID{}). + Optional(), } } diff --git a/entc/integration/entql_test.go b/entc/integration/entql_test.go index 10406f8b2..b3a6dcb86 100644 --- a/entc/integration/entql_test.go +++ b/entc/integration/entql_test.go @@ -8,6 +8,8 @@ import ( "context" "testing" + "github.com/google/uuid" + "github.com/facebook/ent/entc/integration/ent" "github.com/facebook/ent/entc/integration/ent/pet" "github.com/facebook/ent/entc/integration/ent/user" @@ -36,8 +38,9 @@ func EntQL(t *testing.T, client *ent.Client) { ) require.Equal(nati.ID, uq.OnlyIDX(ctx)) - xabi := client.Pet.Create().SetName("xabi").SetOwner(a8m).SaveX(ctx) - luna := client.Pet.Create().SetName("luna").SetOwner(nati).SaveX(ctx) + u1, u2 := uuid.New(), uuid.New() + xabi := client.Pet.Create().SetName("xabi").SetOwner(a8m).SetUUID(u1).SaveX(ctx) + luna := client.Pet.Create().SetName("luna").SetOwner(nati).SetUUID(u2).SaveX(ctx) uq = client.User.Query() uq.Filter().Where( entql.And( @@ -55,10 +58,17 @@ func EntQL(t *testing.T, client *ent.Client) { ) require.Equal(nati.ID, uq.OnlyIDX(ctx)) + pq := client.Pet.Query() + pq.Filter().WhereUUID(entql.ValueEQ(u1)) + require.Equal(xabi.ID, pq.OnlyIDX(ctx)) + pq = client.Pet.Query() + pq.Filter().WhereUUID(entql.ValueEQ(u2)) + require.Equal(luna.ID, pq.OnlyIDX(ctx)) + uq = client.User.Query() uq.Filter().WhereName(entql.StringEQ("a8m")) require.Equal(a8m.ID, uq.OnlyIDX(ctx)) - pq := client.Pet.Query() + pq = client.Pet.Query() pq.Filter().WhereName(entql.StringOr(entql.StringEQ("xabi"), entql.StringEQ("luna"))) require.Equal([]int{luna.ID, xabi.ID}, pq.Order(ent.Asc(pet.FieldName)).IDsX(ctx)) diff --git a/entc/integration/gremlin/ent/fieldtype.go b/entc/integration/gremlin/ent/fieldtype.go index dddfa7aab..2f821e18d 100644 --- a/entc/integration/gremlin/ent/fieldtype.go +++ b/entc/integration/gremlin/ent/fieldtype.go @@ -18,6 +18,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/role" "github.com/facebook/ent/entc/integration/ent/schema" "github.com/facebook/ent/entc/integration/gremlin/ent/fieldtype" + "github.com/google/uuid" ) // FieldType is the model entity for the FieldType schema. @@ -117,6 +118,8 @@ type FieldType struct { Role role.Role `json:"role,omitempty"` // MAC holds the value of the "mac" field. MAC schema.MAC `json:"mac,omitempty"` + // UUID holds the value of the "uuid" field. + UUID uuid.UUID `json:"uuid,omitempty"` } // FromResponse scans the gremlin response data into FieldType. @@ -173,6 +176,7 @@ func (ft *FieldType) FromResponse(res *gremlin.Response) error { NullFloat sql.NullFloat64 `json:"null_float,omitempty"` Role role.Role `json:"role,omitempty"` MAC schema.MAC `json:"mac,omitempty"` + UUID uuid.UUID `json:"uuid,omitempty"` } if err := vmap.Decode(&scanft); err != nil { return err @@ -224,6 +228,7 @@ func (ft *FieldType) FromResponse(res *gremlin.Response) error { ft.NullFloat = scanft.NullFloat ft.Role = scanft.Role ft.MAC = scanft.MAC + ft.UUID = scanft.UUID return nil } @@ -360,6 +365,8 @@ func (ft *FieldType) String() string { builder.WriteString(fmt.Sprintf("%v", ft.Role)) builder.WriteString(", mac=") builder.WriteString(fmt.Sprintf("%v", ft.MAC)) + builder.WriteString(", uuid=") + builder.WriteString(fmt.Sprintf("%v", ft.UUID)) builder.WriteByte(')') return builder.String() } @@ -421,6 +428,7 @@ func (ft *FieldTypes) FromResponse(res *gremlin.Response) error { NullFloat sql.NullFloat64 `json:"null_float,omitempty"` Role role.Role `json:"role,omitempty"` MAC schema.MAC `json:"mac,omitempty"` + UUID uuid.UUID `json:"uuid,omitempty"` } if err := vmap.Decode(&scanft); err != nil { return err @@ -474,6 +482,7 @@ func (ft *FieldTypes) FromResponse(res *gremlin.Response) error { NullFloat: v.NullFloat, Role: v.Role, MAC: v.MAC, + UUID: v.UUID, }) } return nil diff --git a/entc/integration/gremlin/ent/fieldtype/fieldtype.go b/entc/integration/gremlin/ent/fieldtype/fieldtype.go index 9f09534c8..0fd94f4f2 100644 --- a/entc/integration/gremlin/ent/fieldtype/fieldtype.go +++ b/entc/integration/gremlin/ent/fieldtype/fieldtype.go @@ -109,6 +109,8 @@ const ( FieldRole = "role" // FieldMAC holds the string denoting the mac field in the database. FieldMAC = "mac" + // FieldUUID holds the string denoting the uuid field in the database. + FieldUUID = "uuid" ) var ( diff --git a/entc/integration/gremlin/ent/fieldtype/where.go b/entc/integration/gremlin/ent/fieldtype/where.go index 7718a5387..42db0cce0 100644 --- a/entc/integration/gremlin/ent/fieldtype/where.go +++ b/entc/integration/gremlin/ent/fieldtype/where.go @@ -18,6 +18,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/role" "github.com/facebook/ent/entc/integration/ent/schema" "github.com/facebook/ent/entc/integration/gremlin/ent/predicate" + "github.com/google/uuid" ) // ID filters vertices based on their identifier. @@ -402,6 +403,13 @@ func MAC(v schema.MAC) predicate.FieldType { }) } +// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ. +func UUID(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.EQ(v)) + }) +} + // IntEQ applies the EQ predicate on the "int" field. func IntEQ(v int) predicate.FieldType { return predicate.FieldType(func(t *dsl.Traversal) { @@ -3832,6 +3840,84 @@ func MACNotNil() predicate.FieldType { }) } +// UUIDEQ applies the EQ predicate on the "uuid" field. +func UUIDEQ(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.EQ(v)) + }) +} + +// UUIDNEQ applies the NEQ predicate on the "uuid" field. +func UUIDNEQ(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.NEQ(v)) + }) +} + +// UUIDIn applies the In predicate on the "uuid" field. +func UUIDIn(vs ...uuid.UUID) predicate.FieldType { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.Within(v...)) + }) +} + +// UUIDNotIn applies the NotIn predicate on the "uuid" field. +func UUIDNotIn(vs ...uuid.UUID) predicate.FieldType { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.Without(v...)) + }) +} + +// UUIDGT applies the GT predicate on the "uuid" field. +func UUIDGT(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.GT(v)) + }) +} + +// UUIDGTE applies the GTE predicate on the "uuid" field. +func UUIDGTE(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.GTE(v)) + }) +} + +// UUIDLT applies the LT predicate on the "uuid" field. +func UUIDLT(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.LT(v)) + }) +} + +// UUIDLTE applies the LTE predicate on the "uuid" field. +func UUIDLTE(v uuid.UUID) predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.LTE(v)) + }) +} + +// UUIDIsNil applies the IsNil predicate on the "uuid" field. +func UUIDIsNil() predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.HasLabel(Label).HasNot(FieldUUID) + }) +} + +// UUIDNotNil applies the NotNil predicate on the "uuid" field. +func UUIDNotNil() predicate.FieldType { + return predicate.FieldType(func(t *dsl.Traversal) { + t.HasLabel(Label).Has(FieldUUID) + }) +} + // And groups list of predicates with the AND operator between them. func And(predicates ...predicate.FieldType) predicate.FieldType { return predicate.FieldType(func(tr *dsl.Traversal) { diff --git a/entc/integration/gremlin/ent/fieldtype_create.go b/entc/integration/gremlin/ent/fieldtype_create.go index 7bb90d99f..4ba4722cd 100644 --- a/entc/integration/gremlin/ent/fieldtype_create.go +++ b/entc/integration/gremlin/ent/fieldtype_create.go @@ -21,6 +21,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/role" "github.com/facebook/ent/entc/integration/ent/schema" "github.com/facebook/ent/entc/integration/gremlin/ent/fieldtype" + "github.com/google/uuid" ) // FieldTypeCreate is the builder for creating a FieldType entity. @@ -554,6 +555,12 @@ func (ftc *FieldTypeCreate) SetMAC(s schema.MAC) *FieldTypeCreate { return ftc } +// SetUUID sets the uuid field. +func (ftc *FieldTypeCreate) SetUUID(u uuid.UUID) *FieldTypeCreate { + ftc.mutation.SetUUID(u) + return ftc +} + // Mutation returns the FieldTypeMutation object of the builder. func (ftc *FieldTypeCreate) Mutation() *FieldTypeMutation { return ftc.mutation @@ -821,6 +828,9 @@ func (ftc *FieldTypeCreate) gremlin() *dsl.Traversal { if value, ok := ftc.mutation.MAC(); ok { v.Property(dsl.Single, fieldtype.FieldMAC, value) } + if value, ok := ftc.mutation.UUID(); ok { + v.Property(dsl.Single, fieldtype.FieldUUID, value) + } return v.ValueMap(true) } diff --git a/entc/integration/gremlin/ent/fieldtype_update.go b/entc/integration/gremlin/ent/fieldtype_update.go index cae1fa8b2..5c2856a6d 100644 --- a/entc/integration/gremlin/ent/fieldtype_update.go +++ b/entc/integration/gremlin/ent/fieldtype_update.go @@ -22,6 +22,7 @@ import ( "github.com/facebook/ent/entc/integration/ent/schema" "github.com/facebook/ent/entc/integration/gremlin/ent/fieldtype" "github.com/facebook/ent/entc/integration/gremlin/ent/predicate" + "github.com/google/uuid" ) // FieldTypeUpdate is the builder for updating FieldType entities. @@ -1006,6 +1007,18 @@ func (ftu *FieldTypeUpdate) ClearMAC() *FieldTypeUpdate { return ftu } +// SetUUID sets the uuid field. +func (ftu *FieldTypeUpdate) SetUUID(u uuid.UUID) *FieldTypeUpdate { + ftu.mutation.SetUUID(u) + return ftu +} + +// ClearUUID clears the value of uuid. +func (ftu *FieldTypeUpdate) ClearUUID() *FieldTypeUpdate { + ftu.mutation.ClearUUID() + return ftu +} + // Mutation returns the FieldTypeMutation object of the builder. func (ftu *FieldTypeUpdate) Mutation() *FieldTypeMutation { return ftu.mutation @@ -1348,6 +1361,9 @@ func (ftu *FieldTypeUpdate) gremlin() *dsl.Traversal { if value, ok := ftu.mutation.MAC(); ok { v.Property(dsl.Single, fieldtype.FieldMAC, value) } + if value, ok := ftu.mutation.UUID(); ok { + v.Property(dsl.Single, fieldtype.FieldUUID, value) + } var properties []interface{} if ftu.mutation.OptionalIntCleared() { properties = append(properties, fieldtype.FieldOptionalInt) @@ -1469,6 +1485,9 @@ func (ftu *FieldTypeUpdate) gremlin() *dsl.Traversal { if ftu.mutation.MACCleared() { properties = append(properties, fieldtype.FieldMAC) } + if ftu.mutation.UUIDCleared() { + properties = append(properties, fieldtype.FieldUUID) + } if len(properties) > 0 { v.SideEffect(__.Properties(properties...).Drop()) } @@ -2453,6 +2472,18 @@ func (ftuo *FieldTypeUpdateOne) ClearMAC() *FieldTypeUpdateOne { return ftuo } +// SetUUID sets the uuid field. +func (ftuo *FieldTypeUpdateOne) SetUUID(u uuid.UUID) *FieldTypeUpdateOne { + ftuo.mutation.SetUUID(u) + return ftuo +} + +// ClearUUID clears the value of uuid. +func (ftuo *FieldTypeUpdateOne) ClearUUID() *FieldTypeUpdateOne { + ftuo.mutation.ClearUUID() + return ftuo +} + // Mutation returns the FieldTypeMutation object of the builder. func (ftuo *FieldTypeUpdateOne) Mutation() *FieldTypeMutation { return ftuo.mutation @@ -2800,6 +2831,9 @@ func (ftuo *FieldTypeUpdateOne) gremlin(id string) *dsl.Traversal { if value, ok := ftuo.mutation.MAC(); ok { v.Property(dsl.Single, fieldtype.FieldMAC, value) } + if value, ok := ftuo.mutation.UUID(); ok { + v.Property(dsl.Single, fieldtype.FieldUUID, value) + } var properties []interface{} if ftuo.mutation.OptionalIntCleared() { properties = append(properties, fieldtype.FieldOptionalInt) @@ -2921,6 +2955,9 @@ func (ftuo *FieldTypeUpdateOne) gremlin(id string) *dsl.Traversal { if ftuo.mutation.MACCleared() { properties = append(properties, fieldtype.FieldMAC) } + if ftuo.mutation.UUIDCleared() { + properties = append(properties, fieldtype.FieldUUID) + } if len(properties) > 0 { v.SideEffect(__.Properties(properties...).Drop()) } diff --git a/entc/integration/gremlin/ent/mutation.go b/entc/integration/gremlin/ent/mutation.go index 60cb4681a..619929599 100644 --- a/entc/integration/gremlin/ent/mutation.go +++ b/entc/integration/gremlin/ent/mutation.go @@ -30,6 +30,7 @@ import ( "github.com/facebook/ent/entc/integration/gremlin/ent/spec" "github.com/facebook/ent/entc/integration/gremlin/ent/task" "github.com/facebook/ent/entc/integration/gremlin/ent/user" + "github.com/google/uuid" "github.com/facebook/ent" ) @@ -1302,6 +1303,7 @@ type FieldTypeMutation struct { null_float *sql.NullFloat64 role *role.Role mac *schema.MAC + uuid *uuid.UUID clearedFields map[string]struct{} done bool oldValue func(context.Context) (*FieldType, error) @@ -4213,6 +4215,56 @@ func (m *FieldTypeMutation) ResetMAC() { delete(m.clearedFields, fieldtype.FieldMAC) } +// SetUUID sets the uuid field. +func (m *FieldTypeMutation) SetUUID(u uuid.UUID) { + m.uuid = &u +} + +// UUID returns the uuid value in the mutation. +func (m *FieldTypeMutation) UUID() (r uuid.UUID, exists bool) { + v := m.uuid + if v == nil { + return + } + return *v, true +} + +// OldUUID returns the old uuid value of the FieldType. +// If the FieldType object wasn't provided to the builder, the object is fetched +// from the database. +// An error is returned if the mutation operation is not UpdateOne, or database query fails. +func (m *FieldTypeMutation) OldUUID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldUUID is allowed only on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldUUID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUUID: %w", err) + } + return oldValue.UUID, nil +} + +// ClearUUID clears the value of uuid. +func (m *FieldTypeMutation) ClearUUID() { + m.uuid = nil + m.clearedFields[fieldtype.FieldUUID] = struct{}{} +} + +// UUIDCleared returns if the field uuid was cleared in this mutation. +func (m *FieldTypeMutation) UUIDCleared() bool { + _, ok := m.clearedFields[fieldtype.FieldUUID] + return ok +} + +// ResetUUID reset all changes of the "uuid" field. +func (m *FieldTypeMutation) ResetUUID() { + m.uuid = nil + delete(m.clearedFields, fieldtype.FieldUUID) +} + // Op returns the operation name. func (m *FieldTypeMutation) Op() Op { return m.op @@ -4227,7 +4279,7 @@ func (m *FieldTypeMutation) Type() string { // this mutation. Note that, in order to get all numeric // fields that were in/decremented, call AddedFields(). func (m *FieldTypeMutation) Fields() []string { - fields := make([]string, 0, 46) + fields := make([]string, 0, 47) if m.int != nil { fields = append(fields, fieldtype.FieldInt) } @@ -4366,6 +4418,9 @@ func (m *FieldTypeMutation) Fields() []string { if m.mac != nil { fields = append(fields, fieldtype.FieldMAC) } + if m.uuid != nil { + fields = append(fields, fieldtype.FieldUUID) + } return fields } @@ -4466,6 +4521,8 @@ func (m *FieldTypeMutation) Field(name string) (ent.Value, bool) { return m.Role() case fieldtype.FieldMAC: return m.MAC() + case fieldtype.FieldUUID: + return m.UUID() } return nil, false } @@ -4567,6 +4624,8 @@ func (m *FieldTypeMutation) OldField(ctx context.Context, name string) (ent.Valu return m.OldRole(ctx) case fieldtype.FieldMAC: return m.OldMAC(ctx) + case fieldtype.FieldUUID: + return m.OldUUID(ctx) } return nil, fmt.Errorf("unknown FieldType field %s", name) } @@ -4898,6 +4957,13 @@ func (m *FieldTypeMutation) SetField(name string, value ent.Value) error { } m.SetMAC(v) return nil + case fieldtype.FieldUUID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUUID(v) + return nil } return fmt.Errorf("unknown FieldType field %s", name) } @@ -5399,6 +5465,9 @@ func (m *FieldTypeMutation) ClearedFields() []string { if m.FieldCleared(fieldtype.FieldMAC) { fields = append(fields, fieldtype.FieldMAC) } + if m.FieldCleared(fieldtype.FieldUUID) { + fields = append(fields, fieldtype.FieldUUID) + } return fields } @@ -5533,6 +5602,9 @@ func (m *FieldTypeMutation) ClearField(name string) error { case fieldtype.FieldMAC: m.ClearMAC() return nil + case fieldtype.FieldUUID: + m.ClearUUID() + return nil } return fmt.Errorf("unknown FieldType nullable field %s", name) } @@ -5680,6 +5752,9 @@ func (m *FieldTypeMutation) ResetField(name string) error { case fieldtype.FieldMAC: m.ResetMAC() return nil + case fieldtype.FieldUUID: + m.ResetUUID() + return nil } return fmt.Errorf("unknown FieldType field %s", name) } @@ -9387,6 +9462,7 @@ type PetMutation struct { typ string id *string name *string + uuid *uuid.UUID clearedFields map[string]struct{} team *string clearedteam bool @@ -9513,6 +9589,56 @@ func (m *PetMutation) ResetName() { m.name = nil } +// SetUUID sets the uuid field. +func (m *PetMutation) SetUUID(u uuid.UUID) { + m.uuid = &u +} + +// UUID returns the uuid value in the mutation. +func (m *PetMutation) UUID() (r uuid.UUID, exists bool) { + v := m.uuid + if v == nil { + return + } + return *v, true +} + +// OldUUID returns the old uuid value of the Pet. +// If the Pet object wasn't provided to the builder, the object is fetched +// from the database. +// An error is returned if the mutation operation is not UpdateOne, or database query fails. +func (m *PetMutation) OldUUID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldUUID is allowed only on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldUUID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUUID: %w", err) + } + return oldValue.UUID, nil +} + +// ClearUUID clears the value of uuid. +func (m *PetMutation) ClearUUID() { + m.uuid = nil + m.clearedFields[pet.FieldUUID] = struct{}{} +} + +// UUIDCleared returns if the field uuid was cleared in this mutation. +func (m *PetMutation) UUIDCleared() bool { + _, ok := m.clearedFields[pet.FieldUUID] + return ok +} + +// ResetUUID reset all changes of the "uuid" field. +func (m *PetMutation) ResetUUID() { + m.uuid = nil + delete(m.clearedFields, pet.FieldUUID) +} + // SetTeamID sets the team edge to User by id. func (m *PetMutation) SetTeamID(id string) { m.team = &id @@ -9605,10 +9731,13 @@ func (m *PetMutation) Type() string { // this mutation. Note that, in order to get all numeric // fields that were in/decremented, call AddedFields(). func (m *PetMutation) Fields() []string { - fields := make([]string, 0, 1) + fields := make([]string, 0, 2) if m.name != nil { fields = append(fields, pet.FieldName) } + if m.uuid != nil { + fields = append(fields, pet.FieldUUID) + } return fields } @@ -9619,6 +9748,8 @@ func (m *PetMutation) Field(name string) (ent.Value, bool) { switch name { case pet.FieldName: return m.Name() + case pet.FieldUUID: + return m.UUID() } return nil, false } @@ -9630,6 +9761,8 @@ func (m *PetMutation) OldField(ctx context.Context, name string) (ent.Value, err switch name { case pet.FieldName: return m.OldName(ctx) + case pet.FieldUUID: + return m.OldUUID(ctx) } return nil, fmt.Errorf("unknown Pet field %s", name) } @@ -9646,6 +9779,13 @@ func (m *PetMutation) SetField(name string, value ent.Value) error { } m.SetName(v) return nil + case pet.FieldUUID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUUID(v) + return nil } return fmt.Errorf("unknown Pet field %s", name) } @@ -9675,7 +9815,11 @@ func (m *PetMutation) AddField(name string, value ent.Value) error { // ClearedFields returns all nullable fields that were cleared // during this mutation. func (m *PetMutation) ClearedFields() []string { - return nil + var fields []string + if m.FieldCleared(pet.FieldUUID) { + fields = append(fields, pet.FieldUUID) + } + return fields } // FieldCleared returns a boolean indicates if this field was @@ -9688,6 +9832,11 @@ func (m *PetMutation) FieldCleared(name string) bool { // ClearField clears the value for the given name. It returns an // error if the field is not defined in the schema. func (m *PetMutation) ClearField(name string) error { + switch name { + case pet.FieldUUID: + m.ClearUUID() + return nil + } return fmt.Errorf("unknown Pet nullable field %s", name) } @@ -9699,6 +9848,9 @@ func (m *PetMutation) ResetField(name string) error { case pet.FieldName: m.ResetName() return nil + case pet.FieldUUID: + m.ResetUUID() + return nil } return fmt.Errorf("unknown Pet field %s", name) } diff --git a/entc/integration/gremlin/ent/pet.go b/entc/integration/gremlin/ent/pet.go index 30c37021e..6a4e271c3 100644 --- a/entc/integration/gremlin/ent/pet.go +++ b/entc/integration/gremlin/ent/pet.go @@ -12,6 +12,7 @@ import ( "github.com/facebook/ent/dialect/gremlin" "github.com/facebook/ent/entc/integration/gremlin/ent/user" + "github.com/google/uuid" ) // Pet is the model entity for the Pet schema. @@ -21,6 +22,8 @@ type Pet struct { ID string `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` + // UUID holds the value of the "uuid" field. + UUID uuid.UUID `json:"uuid,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the PetQuery when eager-loading is set. Edges PetEdges `json:"edges"` @@ -72,14 +75,16 @@ func (pe *Pet) FromResponse(res *gremlin.Response) error { return err } var scanpe struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + UUID uuid.UUID `json:"uuid,omitempty"` } if err := vmap.Decode(&scanpe); err != nil { return err } pe.ID = scanpe.ID pe.Name = scanpe.Name + pe.UUID = scanpe.UUID return nil } @@ -118,6 +123,8 @@ func (pe *Pet) String() string { builder.WriteString(fmt.Sprintf("id=%v", pe.ID)) builder.WriteString(", name=") builder.WriteString(pe.Name) + builder.WriteString(", uuid=") + builder.WriteString(fmt.Sprintf("%v", pe.UUID)) builder.WriteByte(')') return builder.String() } @@ -132,8 +139,9 @@ func (pe *Pets) FromResponse(res *gremlin.Response) error { return err } var scanpe []struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + UUID uuid.UUID `json:"uuid,omitempty"` } if err := vmap.Decode(&scanpe); err != nil { return err @@ -142,6 +150,7 @@ func (pe *Pets) FromResponse(res *gremlin.Response) error { *pe = append(*pe, &Pet{ ID: v.ID, Name: v.Name, + UUID: v.UUID, }) } return nil diff --git a/entc/integration/gremlin/ent/pet/pet.go b/entc/integration/gremlin/ent/pet/pet.go index 8ade11179..0bdea13d8 100644 --- a/entc/integration/gremlin/ent/pet/pet.go +++ b/entc/integration/gremlin/ent/pet/pet.go @@ -13,6 +13,8 @@ const ( FieldID = "id" // FieldName holds the string denoting the name field in the database. FieldName = "name" + // FieldUUID holds the string denoting the uuid field in the database. + FieldUUID = "uuid" // EdgeTeam holds the string denoting the team edge name in mutations. EdgeTeam = "team" diff --git a/entc/integration/gremlin/ent/pet/where.go b/entc/integration/gremlin/ent/pet/where.go index c76b6f6ae..50553f154 100644 --- a/entc/integration/gremlin/ent/pet/where.go +++ b/entc/integration/gremlin/ent/pet/where.go @@ -11,6 +11,7 @@ import ( "github.com/facebook/ent/dialect/gremlin/graph/dsl/__" "github.com/facebook/ent/dialect/gremlin/graph/dsl/p" "github.com/facebook/ent/entc/integration/gremlin/ent/predicate" + "github.com/google/uuid" ) // ID filters vertices based on their identifier. @@ -91,6 +92,13 @@ func Name(v string) predicate.Pet { }) } +// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ. +func UUID(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.EQ(v)) + }) +} + // NameEQ applies the EQ predicate on the "name" field. func NameEQ(v string) predicate.Pet { return predicate.Pet(func(t *dsl.Traversal) { @@ -176,6 +184,84 @@ func NameHasSuffix(v string) predicate.Pet { }) } +// UUIDEQ applies the EQ predicate on the "uuid" field. +func UUIDEQ(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.EQ(v)) + }) +} + +// UUIDNEQ applies the NEQ predicate on the "uuid" field. +func UUIDNEQ(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.NEQ(v)) + }) +} + +// UUIDIn applies the In predicate on the "uuid" field. +func UUIDIn(vs ...uuid.UUID) predicate.Pet { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.Within(v...)) + }) +} + +// UUIDNotIn applies the NotIn predicate on the "uuid" field. +func UUIDNotIn(vs ...uuid.UUID) predicate.Pet { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.Without(v...)) + }) +} + +// UUIDGT applies the GT predicate on the "uuid" field. +func UUIDGT(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.GT(v)) + }) +} + +// UUIDGTE applies the GTE predicate on the "uuid" field. +func UUIDGTE(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.GTE(v)) + }) +} + +// UUIDLT applies the LT predicate on the "uuid" field. +func UUIDLT(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.LT(v)) + }) +} + +// UUIDLTE applies the LTE predicate on the "uuid" field. +func UUIDLTE(v uuid.UUID) predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.Has(Label, FieldUUID, p.LTE(v)) + }) +} + +// UUIDIsNil applies the IsNil predicate on the "uuid" field. +func UUIDIsNil() predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.HasLabel(Label).HasNot(FieldUUID) + }) +} + +// UUIDNotNil applies the NotNil predicate on the "uuid" field. +func UUIDNotNil() predicate.Pet { + return predicate.Pet(func(t *dsl.Traversal) { + t.HasLabel(Label).Has(FieldUUID) + }) +} + // HasTeam applies the HasEdge predicate on the "team" edge. func HasTeam() predicate.Pet { return predicate.Pet(func(t *dsl.Traversal) { diff --git a/entc/integration/gremlin/ent/pet_create.go b/entc/integration/gremlin/ent/pet_create.go index 20e1177c9..d781caaa4 100644 --- a/entc/integration/gremlin/ent/pet_create.go +++ b/entc/integration/gremlin/ent/pet_create.go @@ -18,6 +18,7 @@ import ( "github.com/facebook/ent/dialect/gremlin/graph/dsl/p" "github.com/facebook/ent/entc/integration/gremlin/ent/pet" "github.com/facebook/ent/entc/integration/gremlin/ent/user" + "github.com/google/uuid" ) // PetCreate is the builder for creating a Pet entity. @@ -33,6 +34,12 @@ func (pc *PetCreate) SetName(s string) *PetCreate { return pc } +// SetUUID sets the uuid field. +func (pc *PetCreate) SetUUID(u uuid.UUID) *PetCreate { + pc.mutation.SetUUID(u) + return pc +} + // SetTeamID sets the team edge to User by id. func (pc *PetCreate) SetTeamID(id string) *PetCreate { pc.mutation.SetTeamID(id) @@ -154,6 +161,9 @@ func (pc *PetCreate) gremlin() *dsl.Traversal { if value, ok := pc.mutation.Name(); ok { v.Property(dsl.Single, pet.FieldName, value) } + if value, ok := pc.mutation.UUID(); ok { + v.Property(dsl.Single, pet.FieldUUID, value) + } for _, id := range pc.mutation.TeamIDs() { v.AddE(user.TeamLabel).From(g.V(id)).InV() constraints = append(constraints, &constraint{ diff --git a/entc/integration/gremlin/ent/pet_update.go b/entc/integration/gremlin/ent/pet_update.go index 7467d74dd..d1a1e835b 100644 --- a/entc/integration/gremlin/ent/pet_update.go +++ b/entc/integration/gremlin/ent/pet_update.go @@ -18,6 +18,7 @@ import ( "github.com/facebook/ent/entc/integration/gremlin/ent/pet" "github.com/facebook/ent/entc/integration/gremlin/ent/predicate" "github.com/facebook/ent/entc/integration/gremlin/ent/user" + "github.com/google/uuid" ) // PetUpdate is the builder for updating Pet entities. @@ -39,6 +40,18 @@ func (pu *PetUpdate) SetName(s string) *PetUpdate { return pu } +// SetUUID sets the uuid field. +func (pu *PetUpdate) SetUUID(u uuid.UUID) *PetUpdate { + pu.mutation.SetUUID(u) + return pu +} + +// ClearUUID clears the value of uuid. +func (pu *PetUpdate) ClearUUID() *PetUpdate { + pu.mutation.ClearUUID() + return pu +} + // SetTeamID sets the team edge to User by id. func (pu *PetUpdate) SetTeamID(id string) *PetUpdate { pu.mutation.SetTeamID(id) @@ -176,6 +189,16 @@ func (pu *PetUpdate) gremlin() *dsl.Traversal { if value, ok := pu.mutation.Name(); ok { v.Property(dsl.Single, pet.FieldName, value) } + if value, ok := pu.mutation.UUID(); ok { + v.Property(dsl.Single, pet.FieldUUID, value) + } + var properties []interface{} + if pu.mutation.UUIDCleared() { + properties = append(properties, pet.FieldUUID) + } + if len(properties) > 0 { + v.SideEffect(__.Properties(properties...).Drop()) + } if pu.mutation.TeamCleared() { tr := rv.Clone().InE(user.TeamLabel).Drop().Iterate() trs = append(trs, tr) @@ -222,6 +245,18 @@ func (puo *PetUpdateOne) SetName(s string) *PetUpdateOne { return puo } +// SetUUID sets the uuid field. +func (puo *PetUpdateOne) SetUUID(u uuid.UUID) *PetUpdateOne { + puo.mutation.SetUUID(u) + return puo +} + +// ClearUUID clears the value of uuid. +func (puo *PetUpdateOne) ClearUUID() *PetUpdateOne { + puo.mutation.ClearUUID() + return puo +} + // SetTeamID sets the team edge to User by id. func (puo *PetUpdateOne) SetTeamID(id string) *PetUpdateOne { puo.mutation.SetTeamID(id) @@ -364,6 +399,16 @@ func (puo *PetUpdateOne) gremlin(id string) *dsl.Traversal { if value, ok := puo.mutation.Name(); ok { v.Property(dsl.Single, pet.FieldName, value) } + if value, ok := puo.mutation.UUID(); ok { + v.Property(dsl.Single, pet.FieldUUID, value) + } + var properties []interface{} + if puo.mutation.UUIDCleared() { + properties = append(properties, pet.FieldUUID) + } + if len(properties) > 0 { + v.SideEffect(__.Properties(properties...).Drop()) + } if puo.mutation.TeamCleared() { tr := rv.Clone().InE(user.TeamLabel).Drop().Iterate() trs = append(trs, tr) diff --git a/entc/integration/privacy/ent/entql.go b/entc/integration/privacy/ent/entql.go index 248313eb0..243c405a6 100644 --- a/entc/integration/privacy/ent/entql.go +++ b/entc/integration/privacy/ent/entql.go @@ -35,6 +35,7 @@ var schemaGraph = func() *sqlgraph.Schema { task.FieldTitle: {Type: field.TypeString, Column: task.FieldTitle}, task.FieldDescription: {Type: field.TypeString, Column: task.FieldDescription}, task.FieldStatus: {Type: field.TypeEnum, Column: task.FieldStatus}, + task.FieldUUID: {Type: field.TypeUUID, Column: task.FieldUUID}, }, } graph.Nodes[1] = &sqlgraph.Node{ @@ -201,6 +202,11 @@ func (f *TaskFilter) WhereStatus(p entql.StringP) { f.Where(p.Field(task.FieldStatus)) } +// WhereUUID applies the entql [16]byte predicate on the uuid field. +func (f *TaskFilter) WhereUUID(p entql.ValueP) { + f.Where(p.Field(task.FieldUUID)) +} + // WhereHasTeams applies a predicate to check if query has an edge teams. func (f *TaskFilter) WhereHasTeams() { f.Where(entql.HasEdge("teams")) diff --git a/entc/integration/privacy/ent/internal/schema.go b/entc/integration/privacy/ent/internal/schema.go index 2dd384bbe..5d7ddc2b5 100644 --- a/entc/integration/privacy/ent/internal/schema.go +++ b/entc/integration/privacy/ent/internal/schema.go @@ -9,4 +9,4 @@ // Package internal holds a loadable version of the latest schema. package internal -const Schema = `{"Schema":"github.com/facebook/ent/entc/integration/privacy/ent/schema","Package":"github.com/facebook/ent/entc/integration/privacy/ent","Schemas":[{"name":"Task","config":{"Table":""},"edges":[{"name":"teams","type":"Team"},{"name":"owner","type":"User","ref_name":"tasks","unique":true,"inverse":true}],"fields":[{"name":"title","type":{"Type":7,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"validators":1,"position":{"Index":0,"MixedIn":false,"MixinIndex":0}},{"name":"description","type":{"Type":7,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":1,"MixedIn":false,"MixinIndex":0}},{"name":"status","type":{"Type":6,"Ident":"task.Status","PkgPath":"","Nillable":false,"RType":null},"enums":[{"N":"planned","V":"planned"},{"N":"in_progress","V":"in_progress"},{"N":"closed","V":"closed"}],"default":true,"default_value":"planned","position":{"Index":2,"MixedIn":false,"MixinIndex":0}}],"hooks":[{"Index":0,"MixedIn":false,"MixinIndex":0}],"policy":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":true,"MixinIndex":1},{"Index":0,"MixedIn":false,"MixinIndex":0}]},{"name":"Team","config":{"Table":""},"edges":[{"name":"tasks","type":"Task","ref_name":"teams","inverse":true},{"name":"users","type":"User","ref_name":"teams","inverse":true}],"fields":[{"name":"name","type":{"Type":7,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"validators":1,"position":{"Index":0,"MixedIn":false,"MixinIndex":0}}],"policy":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":false,"MixinIndex":0}]},{"name":"User","config":{"Table":""},"edges":[{"name":"teams","type":"Team"},{"name":"tasks","type":"Task"}],"fields":[{"name":"name","type":{"Type":7,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"unique":true,"immutable":true,"validators":1,"position":{"Index":0,"MixedIn":false,"MixinIndex":0}},{"name":"age","type":{"Type":17,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":1,"MixedIn":false,"MixinIndex":0}}],"policy":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":true,"MixinIndex":1},{"Index":0,"MixedIn":false,"MixinIndex":0}]}],"Features":["privacy","entql","schema/snapshot"]}` +const Schema = `{"Schema":"github.com/facebook/ent/entc/integration/privacy/ent/schema","Package":"github.com/facebook/ent/entc/integration/privacy/ent","Schemas":[{"name":"Task","config":{"Table":""},"edges":[{"name":"teams","type":"Team"},{"name":"owner","type":"User","ref_name":"tasks","unique":true,"inverse":true}],"fields":[{"name":"title","type":{"Type":7,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"validators":1,"position":{"Index":0,"MixedIn":false,"MixinIndex":0}},{"name":"description","type":{"Type":7,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":1,"MixedIn":false,"MixinIndex":0}},{"name":"status","type":{"Type":6,"Ident":"task.Status","PkgPath":"","Nillable":false,"RType":null},"enums":[{"N":"planned","V":"planned"},{"N":"in_progress","V":"in_progress"},{"N":"closed","V":"closed"}],"default":true,"default_value":"planned","position":{"Index":2,"MixedIn":false,"MixinIndex":0}},{"name":"uuid","type":{"Type":4,"Ident":"uuid.UUID","PkgPath":"github.com/google/uuid","Nillable":true,"RType":null},"optional":true,"position":{"Index":3,"MixedIn":false,"MixinIndex":0}}],"hooks":[{"Index":0,"MixedIn":false,"MixinIndex":0}],"policy":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":true,"MixinIndex":1},{"Index":0,"MixedIn":false,"MixinIndex":0}]},{"name":"Team","config":{"Table":""},"edges":[{"name":"tasks","type":"Task","ref_name":"teams","inverse":true},{"name":"users","type":"User","ref_name":"teams","inverse":true}],"fields":[{"name":"name","type":{"Type":7,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"validators":1,"position":{"Index":0,"MixedIn":false,"MixinIndex":0}}],"policy":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":false,"MixinIndex":0}]},{"name":"User","config":{"Table":""},"edges":[{"name":"teams","type":"Team"},{"name":"tasks","type":"Task"}],"fields":[{"name":"name","type":{"Type":7,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"unique":true,"immutable":true,"validators":1,"position":{"Index":0,"MixedIn":false,"MixinIndex":0}},{"name":"age","type":{"Type":17,"Ident":"","PkgPath":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":1,"MixedIn":false,"MixinIndex":0}}],"policy":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":true,"MixinIndex":1},{"Index":0,"MixedIn":false,"MixinIndex":0}]}],"Features":["privacy","entql","schema/snapshot"]}` diff --git a/entc/integration/privacy/ent/migrate/schema.go b/entc/integration/privacy/ent/migrate/schema.go index e2d517aa9..127776a6b 100644 --- a/entc/integration/privacy/ent/migrate/schema.go +++ b/entc/integration/privacy/ent/migrate/schema.go @@ -18,6 +18,7 @@ var ( {Name: "title", Type: field.TypeString}, {Name: "description", Type: field.TypeString, Nullable: true}, {Name: "status", Type: field.TypeEnum, Enums: []string{"planned", "in_progress", "closed"}, Default: "planned"}, + {Name: "uuid", Type: field.TypeUUID, Nullable: true}, {Name: "user_tasks", Type: field.TypeInt, Nullable: true}, } // TasksTable holds the schema information for the "tasks" table. @@ -28,7 +29,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "tasks_users_tasks", - Columns: []*schema.Column{TasksColumns[4]}, + Columns: []*schema.Column{TasksColumns[5]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, diff --git a/entc/integration/privacy/ent/mutation.go b/entc/integration/privacy/ent/mutation.go index eae929ff9..87b149488 100644 --- a/entc/integration/privacy/ent/mutation.go +++ b/entc/integration/privacy/ent/mutation.go @@ -15,6 +15,7 @@ import ( "github.com/facebook/ent/entc/integration/privacy/ent/task" "github.com/facebook/ent/entc/integration/privacy/ent/team" "github.com/facebook/ent/entc/integration/privacy/ent/user" + "github.com/google/uuid" "github.com/facebook/ent" ) @@ -43,6 +44,7 @@ type TaskMutation struct { title *string description *string status *task.Status + uuid *uuid.UUID clearedFields map[string]struct{} teams map[int]struct{} removedteams map[int]struct{} @@ -257,6 +259,56 @@ func (m *TaskMutation) ResetStatus() { m.status = nil } +// SetUUID sets the uuid field. +func (m *TaskMutation) SetUUID(u uuid.UUID) { + m.uuid = &u +} + +// UUID returns the uuid value in the mutation. +func (m *TaskMutation) UUID() (r uuid.UUID, exists bool) { + v := m.uuid + if v == nil { + return + } + return *v, true +} + +// OldUUID returns the old uuid value of the Task. +// If the Task object wasn't provided to the builder, the object is fetched +// from the database. +// An error is returned if the mutation operation is not UpdateOne, or database query fails. +func (m *TaskMutation) OldUUID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldUUID is allowed only on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldUUID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUUID: %w", err) + } + return oldValue.UUID, nil +} + +// ClearUUID clears the value of uuid. +func (m *TaskMutation) ClearUUID() { + m.uuid = nil + m.clearedFields[task.FieldUUID] = struct{}{} +} + +// UUIDCleared returns if the field uuid was cleared in this mutation. +func (m *TaskMutation) UUIDCleared() bool { + _, ok := m.clearedFields[task.FieldUUID] + return ok +} + +// ResetUUID reset all changes of the "uuid" field. +func (m *TaskMutation) ResetUUID() { + m.uuid = nil + delete(m.clearedFields, task.FieldUUID) +} + // AddTeamIDs adds the teams edge to Team by ids. func (m *TaskMutation) AddTeamIDs(ids ...int) { if m.teams == nil { @@ -363,7 +415,7 @@ func (m *TaskMutation) Type() string { // this mutation. Note that, in order to get all numeric // fields that were in/decremented, call AddedFields(). func (m *TaskMutation) Fields() []string { - fields := make([]string, 0, 3) + fields := make([]string, 0, 4) if m.title != nil { fields = append(fields, task.FieldTitle) } @@ -373,6 +425,9 @@ func (m *TaskMutation) Fields() []string { if m.status != nil { fields = append(fields, task.FieldStatus) } + if m.uuid != nil { + fields = append(fields, task.FieldUUID) + } return fields } @@ -387,6 +442,8 @@ func (m *TaskMutation) Field(name string) (ent.Value, bool) { return m.Description() case task.FieldStatus: return m.Status() + case task.FieldUUID: + return m.UUID() } return nil, false } @@ -402,6 +459,8 @@ func (m *TaskMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldDescription(ctx) case task.FieldStatus: return m.OldStatus(ctx) + case task.FieldUUID: + return m.OldUUID(ctx) } return nil, fmt.Errorf("unknown Task field %s", name) } @@ -432,6 +491,13 @@ func (m *TaskMutation) SetField(name string, value ent.Value) error { } m.SetStatus(v) return nil + case task.FieldUUID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUUID(v) + return nil } return fmt.Errorf("unknown Task field %s", name) } @@ -465,6 +531,9 @@ func (m *TaskMutation) ClearedFields() []string { if m.FieldCleared(task.FieldDescription) { fields = append(fields, task.FieldDescription) } + if m.FieldCleared(task.FieldUUID) { + fields = append(fields, task.FieldUUID) + } return fields } @@ -482,6 +551,9 @@ func (m *TaskMutation) ClearField(name string) error { case task.FieldDescription: m.ClearDescription() return nil + case task.FieldUUID: + m.ClearUUID() + return nil } return fmt.Errorf("unknown Task nullable field %s", name) } @@ -500,6 +572,9 @@ func (m *TaskMutation) ResetField(name string) error { case task.FieldStatus: m.ResetStatus() return nil + case task.FieldUUID: + m.ResetUUID() + return nil } return fmt.Errorf("unknown Task field %s", name) } diff --git a/entc/integration/privacy/ent/schema/task.go b/entc/integration/privacy/ent/schema/task.go index 9cda3d6ad..e9ff9a282 100644 --- a/entc/integration/privacy/ent/schema/task.go +++ b/entc/integration/privacy/ent/schema/task.go @@ -10,6 +10,7 @@ import ( "github.com/facebook/ent/entc/integration/privacy/rule" "github.com/facebook/ent/schema/edge" "github.com/facebook/ent/schema/field" + "github.com/google/uuid" ) // Task defines the schema of a task. @@ -35,6 +36,8 @@ func (Task) Fields() []ent.Field { field.Enum("status"). Values("planned", "in_progress", "closed"). Default("planned"), + field.UUID("uuid", uuid.UUID{}). + Optional(), } } diff --git a/entc/integration/privacy/ent/task.go b/entc/integration/privacy/ent/task.go index 4bc10841d..eee43d10f 100644 --- a/entc/integration/privacy/ent/task.go +++ b/entc/integration/privacy/ent/task.go @@ -13,6 +13,7 @@ import ( "github.com/facebook/ent/dialect/sql" "github.com/facebook/ent/entc/integration/privacy/ent/task" "github.com/facebook/ent/entc/integration/privacy/ent/user" + "github.com/google/uuid" ) // Task is the model entity for the Task schema. @@ -26,6 +27,8 @@ type Task struct { Description string `json:"description,omitempty"` // Status holds the value of the "status" field. Status task.Status `json:"status,omitempty"` + // UUID holds the value of the "uuid" field. + UUID uuid.UUID `json:"uuid,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the TaskQuery when eager-loading is set. Edges TaskEdges `json:"edges"` @@ -73,6 +76,7 @@ func (*Task) scanValues() []interface{} { &sql.NullString{}, // title &sql.NullString{}, // description &sql.NullString{}, // status + &uuid.UUID{}, // uuid } } @@ -110,7 +114,12 @@ func (t *Task) assignValues(values ...interface{}) error { } else if value.Valid { t.Status = task.Status(value.String) } - values = values[3:] + if value, ok := values[3].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field uuid", values[3]) + } else if value != nil { + t.UUID = *value + } + values = values[4:] if len(values) == len(task.ForeignKeys) { if value, ok := values[0].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field user_tasks", value) @@ -161,6 +170,8 @@ func (t *Task) String() string { builder.WriteString(t.Description) builder.WriteString(", status=") builder.WriteString(fmt.Sprintf("%v", t.Status)) + builder.WriteString(", uuid=") + builder.WriteString(fmt.Sprintf("%v", t.UUID)) builder.WriteByte(')') return builder.String() } diff --git a/entc/integration/privacy/ent/task/task.go b/entc/integration/privacy/ent/task/task.go index 1b0ac4c6c..0a8d185f6 100644 --- a/entc/integration/privacy/ent/task/task.go +++ b/entc/integration/privacy/ent/task/task.go @@ -23,6 +23,8 @@ const ( FieldDescription = "description" // FieldStatus holds the string denoting the status field in the database. FieldStatus = "status" + // FieldUUID holds the string denoting the uuid field in the database. + FieldUUID = "uuid" // EdgeTeams holds the string denoting the teams edge name in mutations. EdgeTeams = "teams" @@ -51,6 +53,7 @@ var Columns = []string{ FieldTitle, FieldDescription, FieldStatus, + FieldUUID, } // ForeignKeys holds the SQL foreign-keys that are owned by the Task type. diff --git a/entc/integration/privacy/ent/task/where.go b/entc/integration/privacy/ent/task/where.go index 35c0b1823..be33812f6 100644 --- a/entc/integration/privacy/ent/task/where.go +++ b/entc/integration/privacy/ent/task/where.go @@ -10,6 +10,7 @@ import ( "github.com/facebook/ent/dialect/sql" "github.com/facebook/ent/dialect/sql/sqlgraph" "github.com/facebook/ent/entc/integration/privacy/ent/predicate" + "github.com/google/uuid" ) // ID filters vertices based on their identifier. @@ -109,6 +110,13 @@ func Description(v string) predicate.Task { }) } +// UUID applies equality check predicate on the "uuid" field. It's identical to UUIDEQ. +func UUID(v uuid.UUID) predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUUID), v)) + }) +} + // TitleEQ applies the EQ predicate on the "title" field. func TitleEQ(v string) predicate.Task { return predicate.Task(func(s *sql.Selector) { @@ -393,6 +401,96 @@ func StatusNotIn(vs ...Status) predicate.Task { }) } +// UUIDEQ applies the EQ predicate on the "uuid" field. +func UUIDEQ(v uuid.UUID) predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUUID), v)) + }) +} + +// UUIDNEQ applies the NEQ predicate on the "uuid" field. +func UUIDNEQ(v uuid.UUID) predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldUUID), v)) + }) +} + +// UUIDIn applies the In predicate on the "uuid" field. +func UUIDIn(vs ...uuid.UUID) predicate.Task { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Task(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(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldUUID), v...)) + }) +} + +// UUIDNotIn applies the NotIn predicate on the "uuid" field. +func UUIDNotIn(vs ...uuid.UUID) predicate.Task { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Task(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(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldUUID), v...)) + }) +} + +// UUIDGT applies the GT predicate on the "uuid" field. +func UUIDGT(v uuid.UUID) predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldUUID), v)) + }) +} + +// UUIDGTE applies the GTE predicate on the "uuid" field. +func UUIDGTE(v uuid.UUID) predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldUUID), v)) + }) +} + +// UUIDLT applies the LT predicate on the "uuid" field. +func UUIDLT(v uuid.UUID) predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldUUID), v)) + }) +} + +// UUIDLTE applies the LTE predicate on the "uuid" field. +func UUIDLTE(v uuid.UUID) predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldUUID), v)) + }) +} + +// UUIDIsNil applies the IsNil predicate on the "uuid" field. +func UUIDIsNil() predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldUUID))) + }) +} + +// UUIDNotNil applies the NotNil predicate on the "uuid" field. +func UUIDNotNil() predicate.Task { + return predicate.Task(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldUUID))) + }) +} + // HasTeams applies the HasEdge predicate on the "teams" edge. func HasTeams() predicate.Task { return predicate.Task(func(s *sql.Selector) { diff --git a/entc/integration/privacy/ent/task_create.go b/entc/integration/privacy/ent/task_create.go index 69736b3a5..a0877c6de 100644 --- a/entc/integration/privacy/ent/task_create.go +++ b/entc/integration/privacy/ent/task_create.go @@ -16,6 +16,7 @@ import ( "github.com/facebook/ent/entc/integration/privacy/ent/team" "github.com/facebook/ent/entc/integration/privacy/ent/user" "github.com/facebook/ent/schema/field" + "github.com/google/uuid" ) // TaskCreate is the builder for creating a Task entity. @@ -59,6 +60,12 @@ func (tc *TaskCreate) SetNillableStatus(t *task.Status) *TaskCreate { return tc } +// SetUUID sets the uuid field. +func (tc *TaskCreate) SetUUID(u uuid.UUID) *TaskCreate { + tc.mutation.SetUUID(u) + return tc +} + // AddTeamIDs adds the teams edge to Team by ids. func (tc *TaskCreate) AddTeamIDs(ids ...int) *TaskCreate { tc.mutation.AddTeamIDs(ids...) @@ -220,6 +227,14 @@ func (tc *TaskCreate) createSpec() (*Task, *sqlgraph.CreateSpec) { }) _node.Status = value } + if value, ok := tc.mutation.UUID(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: task.FieldUUID, + }) + _node.UUID = value + } if nodes := tc.mutation.TeamsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/entc/integration/privacy/ent/task_update.go b/entc/integration/privacy/ent/task_update.go index 744d4c4ca..e9a30b9ec 100644 --- a/entc/integration/privacy/ent/task_update.go +++ b/entc/integration/privacy/ent/task_update.go @@ -17,6 +17,7 @@ import ( "github.com/facebook/ent/entc/integration/privacy/ent/team" "github.com/facebook/ent/entc/integration/privacy/ent/user" "github.com/facebook/ent/schema/field" + "github.com/google/uuid" ) // TaskUpdate is the builder for updating Task entities. @@ -72,6 +73,18 @@ func (tu *TaskUpdate) SetNillableStatus(t *task.Status) *TaskUpdate { return tu } +// SetUUID sets the uuid field. +func (tu *TaskUpdate) SetUUID(u uuid.UUID) *TaskUpdate { + tu.mutation.SetUUID(u) + return tu +} + +// ClearUUID clears the value of uuid. +func (tu *TaskUpdate) ClearUUID() *TaskUpdate { + tu.mutation.ClearUUID() + return tu +} + // AddTeamIDs adds the teams edge to Team by ids. func (tu *TaskUpdate) AddTeamIDs(ids ...int) *TaskUpdate { tu.mutation.AddTeamIDs(ids...) @@ -255,6 +268,19 @@ func (tu *TaskUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: task.FieldStatus, }) } + if value, ok := tu.mutation.UUID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: task.FieldUUID, + }) + } + if tu.mutation.UUIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: task.FieldUUID, + }) + } if tu.mutation.TeamsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, @@ -402,6 +428,18 @@ func (tuo *TaskUpdateOne) SetNillableStatus(t *task.Status) *TaskUpdateOne { return tuo } +// SetUUID sets the uuid field. +func (tuo *TaskUpdateOne) SetUUID(u uuid.UUID) *TaskUpdateOne { + tuo.mutation.SetUUID(u) + return tuo +} + +// ClearUUID clears the value of uuid. +func (tuo *TaskUpdateOne) ClearUUID() *TaskUpdateOne { + tuo.mutation.ClearUUID() + return tuo +} + // AddTeamIDs adds the teams edge to Team by ids. func (tuo *TaskUpdateOne) AddTeamIDs(ids ...int) *TaskUpdateOne { tuo.mutation.AddTeamIDs(ids...) @@ -583,6 +621,19 @@ func (tuo *TaskUpdateOne) sqlSave(ctx context.Context) (_node *Task, err error) Column: task.FieldStatus, }) } + if value, ok := tuo.mutation.UUID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Value: value, + Column: task.FieldUUID, + }) + } + if tuo.mutation.UUIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeUUID, + Column: task.FieldUUID, + }) + } if tuo.mutation.TeamsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, diff --git a/entql/internal/gen.go b/entql/internal/gen.go index 5f0499664..66cb1b8eb 100644 --- a/entql/internal/gen.go +++ b/entql/internal/gen.go @@ -26,6 +26,7 @@ func main() { "ops": ops, "title": strings.Title, "ident": ident, + "type": typ, }). Parse(string(buf))) b := &bytes.Buffer{} @@ -49,6 +50,7 @@ func main() { field.TypeFloat32, field.TypeFloat64, field.TypeString, + field.TypeUUID, }, }); err != nil { log.Fatal("executing template:", err) @@ -63,7 +65,7 @@ func main() { func ops(t field.Type) []string { switch t { - case field.TypeBool, field.TypeBytes: + case field.TypeBool, field.TypeBytes, field.TypeUUID: return []string{"EQ", "NEQ"} default: return []string{"EQ", "NEQ", "LT", "LTE", "GT", "GTE"} @@ -72,11 +74,20 @@ func ops(t field.Type) []string { func ident(t field.Type) string { switch t { - case field.TypeTime: - return "time" case field.TypeBytes: return "bytes" + case field.TypeTime: + return "time" + case field.TypeUUID: + return "value" default: return t.String() } } + +func typ(t field.Type) string { + if t == field.TypeUUID { + return "driver.Valuer" + } + return t.String() +} diff --git a/entql/internal/types.tmpl b/entql/internal/types.tmpl index 23ee90681..31d722c4e 100644 --- a/entql/internal/types.tmpl +++ b/entql/internal/types.tmpl @@ -7,7 +7,10 @@ package entql -import "time" +import ( + "database/sql/driver" + "time" +) //go:generate go run internal/gen.go @@ -44,7 +47,7 @@ func (*{{ $builder }}) {{ ident $t }}() {} {{ range $op := ops $t }} // {{ $titled }}{{ $op }} applies the {{ $op }} operation on the given value. - func {{ $titled }}{{ $op }}(v {{ $t }}) {{ $iface }} { + func {{ $titled }}{{ $op }}(v {{ type $t }}) {{ $iface }} { field := &Field{} value := &Value{V: v} done := func(name string) { field.Name = name } diff --git a/entql/types.go b/entql/types.go index aa08d4efe..7267a0677 100644 --- a/entql/types.go +++ b/entql/types.go @@ -6,7 +6,10 @@ package entql -import "time" +import ( + "database/sql/driver" + "time" +) //go:generate go run internal/gen.go @@ -1583,3 +1586,73 @@ func StringNot(x StringP) StringP { } return expr } + +// ValueP is the interface for predicates of type [16]byte (`type P[[16]byte]`). +type ValueP interface { + Fielder + value() +} + +// valueP implements the ValueP interface. +type valueP struct { + P + done func(string) +} + +func (p *valueP) Field(name string) P { + p.done(name) + return p.P +} + +func (*valueP) value() {} + +// ValueEQ applies the EQ operation on the given value. +func ValueEQ(v driver.Valuer) ValueP { + field := &Field{} + value := &Value{V: v} + done := func(name string) { field.Name = name } + return &valueP{P: EQ(field, value), done: done} +} + +// ValueNEQ applies the NEQ operation on the given value. +func ValueNEQ(v driver.Valuer) ValueP { + field := &Field{} + value := &Value{V: v} + done := func(name string) { field.Name = name } + return &valueP{P: NEQ(field, value), done: done} +} + +// ValueOr returns a composed predicate that represents the logical OR predicate. +func ValueOr(x, y ValueP, z ...ValueP) ValueP { + expr := &valueP{} + expr.done = func(name string) { + zs := make([]P, len(z)) + for i := range z { + zs[i] = z[i].Field(name) + } + expr.P = Or(x.Field(name), y.Field(name), zs...) + } + return expr +} + +// ValueAnd returns a composed predicate that represents the logical AND predicate. +func ValueAnd(x, y ValueP, z ...ValueP) ValueP { + expr := &valueP{} + expr.done = func(name string) { + zs := make([]P, len(z)) + for i := range z { + zs[i] = z[i].Field(name) + } + expr.P = And(x.Field(name), y.Field(name), zs...) + } + return expr +} + +// ValueNot returns a predicate that represents the logical negation of the given predicate. +func ValueNot(x ValueP) ValueP { + expr := &valueP{} + expr.done = func(name string) { + expr.P = Not(x.Field(name)) + } + return expr +}