From 6e1da6a8910a241c6a19af2a1774ee517e949d74 Mon Sep 17 00:00:00 2001 From: Alex Snast Date: Sun, 5 Jul 2020 14:17:58 +0300 Subject: [PATCH] entc/gen: add `Type.EnumFields` helper (#584) Signed-off-by: Alex Snast --- entc/gen/internal/bindata.go | 4 +-- entc/gen/template/meta.tmpl | 70 ++++++++++++++++++------------------ entc/gen/type.go | 11 ++++++ 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index 478c5cbc1..69f8b302c 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -966,7 +966,7 @@ func templateImportTmpl() (*asset, error) { return a, nil } -var _templateMetaTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x58\x4d\x6f\xdb\x3c\x12\x3e\x4b\xbf\x62\x20\xb8\x40\x1c\x24\x72\xdf\xf7\xb6\x01\x72\xe8\x26\x29\x1a\x6c\x51\x14\x48\xd2\xcb\x62\x51\xd0\xe2\xd0\x26\x4a\x91\x2e\x49\x25\xcd\x0a\xfe\xef\x0b\x0e\x49\x7d\x24\x76\xb7\xed\x25\x10\xc9\x99\x67\x3e\x38\xf3\x70\x9c\xbe\x5f\x9d\x96\x57\x66\xf7\x6c\xe5\x66\xeb\xe1\xef\xb7\x7f\xfd\xe3\x7c\x67\xd1\xa1\xf6\xf0\x9e\x35\xb8\x36\xe6\x1b\xdc\xea\xa6\x86\x77\x4a\x01\x09\x39\x08\xe7\xf6\x11\x79\x5d\xde\x6f\xa5\x03\x67\x3a\xdb\x20\x34\x86\x23\x48\x07\x4a\x36\xa8\x1d\x72\xe8\x34\x47\x0b\x7e\x8b\xf0\x6e\xc7\x9a\x2d\xc2\xdf\xf5\xdb\x7c\x0a\xc2\x74\x9a\x97\x52\xd3\xf9\xc7\xdb\xab\x9b\x4f\x77\x37\x20\xa4\x42\x48\x7b\xd6\x18\x0f\x5c\x5a\x6c\xbc\xb1\xcf\x60\x04\xf8\x89\x31\x6f\x11\xeb\xf2\x74\xb5\xdf\x97\x65\xdf\x03\x47\x21\x35\x42\xd5\xa2\x67\x15\xc4\xcd\x73\x78\x92\x7e\x0b\xf8\xc3\xa3\xe6\xb0\x80\xea\x33\x6b\xbe\xb1\x0d\x56\xb0\xa8\xd3\x27\x9c\xef\xf7\x65\xd1\xf7\xe0\xb1\xdd\x29\xe6\x11\xaa\x2d\x32\x8e\xb6\x82\x3a\xa0\xf4\x3d\x04\xdd\x64\x64\x14\x92\xed\xce\x58\x5f\xc1\x82\x8e\x1a\xa3\x9d\x87\x93\xb2\x58\xad\xe0\x23\x5b\xa3\x82\xad\x51\xdc\x51\x14\xce\x5b\xa9\x37\xa0\x68\x9b\xa3\x36\x3e\x2c\xc3\x49\xdf\x83\x32\x4f\x68\x61\x51\x7f\x62\x2d\xc2\x7e\x0f\xfe\x79\x37\x84\xcf\x99\x67\x6b\xe6\xb0\x2e\x8b\x88\x79\x09\x55\xdf\xc3\xa2\x8e\xab\xfd\xbe\x22\x7b\xb4\x75\x7b\x5d\x5f\x05\x1f\x98\xf6\x01\xe6\x95\xf5\x99\x5d\xc9\x41\x48\x54\xfc\x80\xa1\x43\x60\xd9\xec\xed\x75\x7d\xe7\x8d\x65\x1b\xfc\x17\x3e\x47\xf3\x21\xc5\x96\xe9\x0d\xc2\x42\xc0\xc5\x25\x2c\xea\xf7\x01\xd8\x85\xa4\x14\x74\xba\x88\x96\xc2\x99\x98\xa2\x96\x45\xf6\x3d\x0a\xfc\x5f\xa7\xc7\x64\x89\x21\x5b\xc7\xa2\x28\x66\xb8\xc9\x7f\x71\xd0\xfb\x7c\xb9\x41\x25\x45\x82\x31\x92\x1b\xbe\xc1\x69\x20\xc8\x37\xf1\x04\x0f\xc7\x41\xe7\xbf\x11\x06\x0e\x61\x90\xa6\x0e\x0b\xa9\xa1\xed\x3c\xf3\xd2\x68\x97\xe3\xc8\xb8\x29\x8c\x41\xed\x40\x00\x0b\xdf\xee\x54\xf0\x71\x67\xa5\xf6\x02\x2a\x2e\x99\xc2\xc6\xaf\xde\xb8\x55\xe8\x8b\x55\x93\x1c\x77\xa1\x03\x52\x3a\x20\x35\xc0\x8f\xa1\xb8\x23\x0c\x55\xf6\x92\xca\x3e\x6e\x1c\x87\x7d\x64\x56\xb2\xb5\xc2\x97\xb0\x7d\x0f\x52\xc0\x96\xb9\xfb\x39\xf4\xcf\x2c\xce\x1b\x4e\x0a\x30\xa1\x3f\x3e\x30\x77\x8d\x82\x75\xca\xc7\xc5\x17\xa6\x24\x67\xde\x58\x17\x9a\xa7\x6b\x3f\x18\xf3\xcd\xc5\xa3\xcf\x46\xc9\x26\xdc\x70\x09\x00\x40\x57\xa7\xb3\x00\x5d\xec\x20\x3e\x11\x91\xe2\x90\xf2\x6b\x80\x4b\x60\x9c\x4f\xd6\x7f\x4d\x41\x92\xdf\x45\x06\xd4\x13\x43\x54\x26\x9f\x8c\x47\xf0\x5b\xe6\xa9\x14\x86\xac\xc1\x1a\x95\x79\x02\x66\x43\x01\x48\x2f\x99\x92\xff\x45\x0e\xeb\xe7\xc8\x82\x9d\xf6\xb2\xc5\x88\xb0\x4b\xac\x65\x62\xcd\x0f\xe2\x54\x32\x91\x21\x11\xd8\x6e\xa7\x64\x43\x5b\x35\xdc\x6f\xd1\xa2\x30\x16\xcf\x22\x82\xf4\xe0\xb6\xa6\x53\x1c\xd6\x08\x91\xc5\x70\xe8\xa1\x96\x49\x0d\xcc\x81\x30\x4a\x99\x27\x77\x41\x2a\xf4\xa7\x88\xa2\xf0\x35\x91\xc1\x95\xd1\x42\x6e\x06\x16\xdd\xef\x57\xc9\xcf\x2a\xe9\x4c\x13\xf2\xc8\x6c\x20\xc7\x23\x89\x29\xe2\xf7\xbf\x03\xee\xe4\xe4\x3f\xa8\x7d\x1d\x16\x49\x31\x83\x15\x87\xef\xab\x28\x8a\xb4\x08\x7a\xf1\xf3\x90\x66\xe4\x05\xf7\x82\xad\x62\xa9\x11\xc7\x3d\x38\xb4\xd7\xf4\x98\xf0\x78\x90\x35\x2e\x43\x62\xe9\x21\x49\x1b\x41\x3c\x8a\xcc\x2c\xcc\x08\x51\x4c\xf8\x30\x7b\xce\x08\xa3\xce\x05\x7d\xa2\x8d\x0f\xeb\x5b\x77\xa3\xbb\x76\x99\x64\xa3\xb3\x3c\xc9\x44\xfe\x4c\x1a\x89\x00\x48\x2a\x91\x4f\x96\x9b\xf1\x4f\xde\x7c\x64\xaa\xa3\x92\x69\x2c\xc6\x42\x11\xc6\x66\x36\x7a\x49\xa7\x75\x32\x3e\xc3\x1c\x3b\x31\xb8\x79\x2f\x5b\x8c\x5f\x0f\x0f\x94\x01\xd1\xe9\xe6\x64\x09\x43\x22\x22\xec\x7d\x78\xcb\xc6\xc0\x87\x1c\x0d\x17\x28\xea\x87\x1d\x67\x1e\xaf\x07\x43\xc7\x02\x9f\xc9\xfd\x71\xf8\x1d\xa1\xfc\x61\xf0\x63\xe4\x7f\x14\x2f\x0d\x22\x0b\x51\x4f\x88\x6b\x1a\x2e\xb1\x7f\x8c\x75\x90\x98\x09\xd0\x60\x70\x71\x09\x03\x07\x07\x1f\xe0\xe4\x8d\x5b\x02\x5a\x6b\x6c\x95\x3d\x98\xba\x91\xd3\xa3\x53\x8c\xd2\x01\x0b\xe9\x48\xf8\x39\x11\xd5\x2c\x13\x55\x4a\x05\xdc\xfa\xa0\xd0\x30\xa5\x46\x32\x5a\x77\x52\x71\xb4\x81\xb2\x02\xa7\x80\x63\x8f\x38\x26\x2d\xdb\xa1\x27\xe3\x48\x36\xa6\x8b\xe5\x9c\xed\x57\xa7\x79\x8a\x6b\x3a\xe7\x4d\x1b\xa7\xa1\xe0\x25\xea\xae\x85\xd4\x4a\x34\xf1\x8d\xaf\xf5\x7c\xee\xc8\xd3\x5c\xbe\xb0\xd0\x51\xd9\xee\xea\x14\x4c\x2b\x23\xf7\x66\x1e\x25\x8f\x85\x0d\xb6\xb6\x48\xf6\xea\x68\x20\xbd\xbd\x41\xfd\xe2\x12\xbc\x95\x6d\xa6\xba\x9c\xe7\xbb\xf8\xba\x2f\x26\x1c\x38\x19\x06\xa2\xdd\x14\x8f\x1b\xd0\x8f\x14\xdf\x18\x5f\x48\x26\x09\x4e\x51\xe2\x20\x51\x96\xd3\xd6\x99\x37\x4d\xd8\x5f\x9d\x02\x08\xa9\x39\xe1\x93\x2a\x3d\x35\x47\x1a\x22\xc4\x19\xd3\x35\x63\xad\xaf\x67\x79\x00\x12\x75\x48\xde\xac\x4c\xa5\x00\xfc\x1e\xce\x47\xfb\x5f\xa8\xb9\x92\xcc\xab\x5a\x0e\x08\x14\xe3\x62\x94\x79\x5d\x93\x53\xdf\x26\x61\xc7\xba\x2a\xe2\x6c\x1d\xf3\x35\x67\x00\xb8\x9c\x22\x0d\x5e\xce\x1b\xef\x50\xe1\xbd\xbe\x27\x4a\x09\x8d\x5c\xc3\x28\xff\xab\x69\x79\x1d\xe7\x0c\x39\x8f\x6d\x71\x62\x8b\xa0\xa3\x53\xcb\x32\x55\x9a\xc5\x06\xe5\x23\xda\x60\x63\xf8\x5e\x88\xfa\x9f\xb1\xe1\xa8\xbc\xd3\x75\xc5\xce\x9f\x29\xcd\x6d\x2e\x21\xd6\xe6\xc9\x32\x8f\xa0\x7d\xb0\x6c\xd1\x77\x56\xa7\xad\x97\xfa\xcb\xb2\x28\xf6\xd9\x99\x83\x6c\x74\x3e\xad\xef\x5f\x61\x94\x09\x7a\xe2\x94\x58\x95\x29\xd7\xbf\xc5\x2f\x14\xf3\xc4\xf0\xcf\xc3\x27\x46\x8c\x41\xbb\x27\xe9\x9b\x2d\xbc\x12\xa7\xcb\x6b\x98\xa3\x46\x4b\x97\x2c\x0f\x5c\x72\xe4\x12\x1d\x4e\xe1\x2d\xec\xf7\x67\x2f\x48\xff\xce\xdb\xae\xf1\xef\xd3\x6f\x8d\xbe\x87\x1d\x73\x0d\x53\xf1\xc2\x07\xd9\x8b\x58\xca\xe9\x06\xb4\x54\xb4\x4e\x35\x3f\x3f\x14\xad\xaf\x6f\x82\xff\xe2\x24\x4e\x5a\x23\xbd\x5c\x80\xd4\x94\xeb\x49\x1e\x29\xe5\x07\x5e\xb2\x0b\x78\xf3\xbd\x3a\x7b\x19\x77\xb8\xe5\x62\x4f\x57\x5d\x8c\xd4\x7b\xec\x37\x2e\xcd\xf6\x8c\x73\x19\x66\x06\xa6\xf2\x8f\xdd\x97\x9c\xfd\x6e\x54\x21\xc2\x69\x98\x0e\xb3\xa5\x79\x44\x6b\x25\x8f\xc3\xa5\xb1\xf4\x8f\x00\x43\xe3\xf3\x08\x19\xff\x63\x90\xab\x86\x78\x2f\x31\x73\x3d\xf0\xfc\xf4\x87\xfd\xcc\x9b\xe9\xe4\xf5\xbf\x00\x00\x00\xff\xff\xea\x92\x17\xc5\xc5\x10\x00\x00") +var _templateMetaTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x57\xcd\x6e\xdb\x38\x10\x3e\x4b\x4f\x31\x10\x5c\x20\x0e\x12\xb9\xed\x6d\x03\xe4\xd0\x4d\x52\x34\xd8\xa2\x28\x90\xa4\x97\xc5\xa2\xa0\xc5\x91\x4d\x94\x22\x5d\x92\x72\x9a\x15\xf4\xee\x0b\x0e\x49\x59\x72\xec\x6c\xdb\x8b\x61\x92\x33\xdf\xfc\x70\xe6\xe3\xa8\xeb\x16\xa7\xf9\x95\xde\x3c\x19\xb1\x5a\x3b\x78\xfb\xfa\xcd\x1f\xe7\x1b\x83\x16\x95\x83\xf7\xac\xc2\xa5\xd6\xdf\xe0\x56\x55\x25\xbc\x93\x12\x48\xc8\x82\x3f\x37\x5b\xe4\x65\x7e\xbf\x16\x16\xac\x6e\x4d\x85\x50\x69\x8e\x20\x2c\x48\x51\xa1\xb2\xc8\xa1\x55\x1c\x0d\xb8\x35\xc2\xbb\x0d\xab\xd6\x08\x6f\xcb\xd7\xe9\x14\x6a\xdd\x2a\x9e\x0b\x45\xe7\x1f\x6f\xaf\x6e\x3e\xdd\xdd\x40\x2d\x24\x42\xdc\x33\x5a\x3b\xe0\xc2\x60\xe5\xb4\x79\x02\x5d\x83\x1b\x19\x73\x06\xb1\xcc\x4f\x17\x7d\x9f\xe7\x5d\x07\x1c\x6b\xa1\x10\x8a\x06\x1d\x2b\x20\x6c\x9e\xc3\xa3\x70\x6b\xc0\x1f\x0e\x15\x87\x19\x14\x9f\x59\xf5\x8d\xad\xb0\x80\x59\x19\xff\xc2\x79\xdf\xe7\x59\xd7\x81\xc3\x66\x23\x99\x43\x28\xd6\xc8\x38\x9a\x02\x4a\x8f\xd2\x75\xe0\x75\xa3\x91\x9d\x90\x68\x36\xda\xb8\x02\x66\x74\x54\x69\x65\x1d\x9c\xe4\xd9\x62\x01\x1f\xd9\x12\x25\xac\xb5\xe4\x96\xa2\xb0\xce\x08\xb5\x02\x49\xdb\x1c\x95\x76\x7e\xe9\x4f\xba\x0e\xa4\x7e\x44\x03\xb3\xf2\x13\x6b\x10\xfa\x1e\xdc\xd3\x66\x08\x9f\x33\xc7\x96\xcc\x62\x99\x67\x01\xf3\x12\x8a\xae\x83\x59\x19\x56\x7d\x5f\x90\x3d\xda\xba\xbd\x2e\xaf\xbc\x0f\x4c\x39\x0f\xf3\xcc\xfa\xc4\xae\xe0\x50\x0b\x94\xfc\x80\xa1\x43\x60\xc9\xec\xed\x75\x79\xe7\xb4\x61\x2b\xfc\x0b\x9f\x82\x79\x9f\x62\xc3\xd4\x0a\x61\x56\xc3\xc5\x25\xcc\xca\xf7\x1e\xd8\xfa\xa4\x64\x74\x3a\x0b\x96\xfc\x59\x3d\x46\xcd\xb3\xe4\x7b\x10\xf8\x5f\xa7\x77\xc9\xaa\x87\x6c\x1d\x8b\x22\x9b\xe0\x46\xff\xeb\x83\xde\xa7\xcb\xf5\x2a\x31\x12\x0c\x91\xdc\xf0\x15\x8e\x03\x41\xbe\x0a\x27\x78\x38\x0e\x3a\xff\x85\x30\x70\x08\x83\x34\x95\x5f\x08\x05\x4d\xeb\x98\x13\x5a\xd9\x14\x47\xc2\x8d\x61\x0c\x6a\x07\x02\x98\xb9\x66\x23\xbd\x8f\x1b\x23\x94\xab\xa1\xe0\x82\x49\xac\xdc\xe2\x95\x5d\xf8\xbe\x58\x54\xd1\x71\xeb\x3b\x20\xa6\x03\x62\x03\xfc\x18\x8a\x3b\xc0\x50\x65\xcf\xa9\xec\xc3\xc6\x71\xd8\x2d\x33\x82\x2d\x25\xee\xc3\x76\x1d\x88\x1a\xd6\xcc\xde\x4f\xa1\x5f\xb2\x38\x6d\x38\x51\x83\xf6\xfd\xf1\x81\xd9\x6b\xac\x59\x2b\x5d\x58\x7c\x61\x52\x70\xe6\xb4\xb1\xbe\x79\xda\xe6\x83\xd6\xdf\x6c\x38\xfa\xac\xa5\xa8\xfc\x0d\xe7\x00\x00\x74\x75\x2a\x09\xd0\xc5\x0e\xe2\x23\x11\x51\x1f\x52\x7e\x0e\x70\x09\x8c\xf3\xd1\xfa\xcd\x18\x24\xfa\x9d\x25\x40\x35\x32\x44\x65\xf2\x49\x3b\x04\xb7\x66\x8e\x4a\x61\xc8\x1a\x2c\x51\xea\x47\x60\xc6\x17\x80\x70\x82\x49\xf1\x2f\x72\x58\x3e\x05\x16\x6c\x95\x13\x0d\x06\x84\x4d\x64\x2d\x1d\x6a\x7e\x10\xa7\x92\x09\x0c\x89\xc0\x36\x1b\x29\x2a\xda\x2a\xe1\x7e\x8d\x06\x6b\x6d\xf0\x2c\x20\x08\x07\x76\xad\x5b\xc9\x61\x89\x10\x58\x0c\x87\x1e\x6a\x98\x50\xc0\x2c\xd4\x5a\x4a\xfd\x68\x2f\x48\x85\x7e\xb2\x20\x0a\x5f\x23\x19\x5c\x69\x55\x8b\xd5\xc0\xa2\x7d\xbf\x88\x7e\x16\x51\x67\x9c\x90\x2d\x33\x9e\x1c\x8f\x24\x26\x0b\xff\xff\xf6\xb8\xa3\x93\x7f\x50\xb9\xd2\x2f\xa2\x62\x02\xcb\x0e\xdf\x57\x96\x65\x71\xe1\xf5\xc2\xdf\x43\x9a\x81\x17\xec\x1e\x5b\x85\x52\x23\x8e\x7b\xb0\x68\xae\xe9\x31\xe1\xe1\x20\x69\x5c\xfa\xc4\xd2\x43\x12\x37\xbc\x78\x10\x99\x58\x98\x10\x62\x3d\xe2\xc3\xe4\x39\x23\x8c\x32\x15\xf4\x89\xd2\xce\xaf\x6f\xed\x8d\x6a\x9b\x79\x94\x0d\xce\xf2\x28\x13\xf8\x33\x6a\x44\x02\x20\xa9\x48\x3e\x49\x6e\xc2\x3f\x69\x73\xcb\x64\x4b\x25\x53\x19\x0c\x85\x52\x6b\x93\xd8\x68\x9f\x4e\xcb\x68\x7c\x82\xb9\xeb\x44\xef\xe6\xbd\x68\x30\xfc\x7b\x78\xa0\x0c\xd4\xad\xaa\x4e\xe6\x30\x24\x22\xc0\xde\xfb\xb7\x6c\x17\xf8\x90\xa3\xe1\x02\xeb\xf2\x61\xc3\x99\xc3\xeb\xc1\xd0\xb1\xc0\x27\x72\xbf\x1d\x7e\x4b\x28\xbf\x19\xfc\x2e\xf2\xdf\x8a\x97\x06\x91\x59\x5d\x8e\x88\x6b\x1c\x2e\xb1\x7f\x88\x75\x90\x98\x08\xd0\x60\x70\x71\x09\x03\x07\x7b\x1f\xe0\xe4\x95\x9d\x03\x1a\xa3\x4d\x91\x3c\x18\xbb\x91\xd2\xa3\x62\x8c\xc2\x02\xf3\xe9\x88\xf8\x29\x11\xc5\x24\x13\x45\x4c\x05\xdc\x3a\xaf\x50\x31\x29\x77\x64\xb4\x6c\x85\xe4\x68\x3c\x65\x79\x4e\x01\xcb\xb6\xb8\x4b\x5a\xb2\x43\x4f\xc6\x91\x6c\x8c\x17\xf3\x29\xdb\x2f\x4e\xd3\x14\x57\xb5\xd6\xe9\x26\x4c\x43\xde\x4b\x54\x6d\x03\xb1\x95\x68\xe2\xdb\xbd\xd6\x71\xee\xf0\xad\x13\xbb\x39\x4e\x74\x8b\x53\xd0\x8d\x08\x54\x9b\x68\x93\x1c\xac\x8d\x87\x5e\x23\xc1\x97\x01\x2f\xbc\xb4\xde\xca\xc5\x25\x38\x23\x9a\x44\x6c\x29\xab\x77\xe1\x2d\x9f\x8d\x18\x6f\x98\xbe\x48\xaf\xef\xa3\xf3\x76\xc0\x3e\x52\x69\xbb\x60\xca\x3c\x23\xb9\x31\x48\x18\x1a\xf2\x7c\xd4\x25\x93\xfe\xf0\xdb\x8b\x53\x80\x5a\x28\x4e\xe0\xa4\x48\x8f\xca\x91\xd2\xf7\x21\x86\xa4\x8c\xe9\xe9\xeb\x59\x9a\x74\x6a\x4a\xde\x1e\x47\xe1\x77\x7f\xbc\x33\xfe\x85\x9a\xe8\x48\xc9\x7a\x7d\x8a\x6e\xf6\x42\xe5\x8d\xfd\x1a\x05\x1c\xaa\x27\x0c\xd0\x21\x4f\xd3\x36\x87\xcb\x31\xd0\x8b\xe5\x34\x19\x87\xf6\xee\x86\x32\xe1\x67\xaa\x61\x54\xff\xb9\x64\x3c\x0f\x6f\x02\x9b\x86\xb2\x30\x8f\x11\xe4\xa8\xba\x43\x59\x19\xac\x50\x6c\xd1\x78\xfc\xe1\xff\xac\x2e\xff\x0c\xbd\x44\x55\x1b\xee\x27\xf4\xf4\x44\x67\x6a\x6f\x0e\xa1\x0e\x4f\xe6\x69\xb8\xec\xf2\x2c\x33\xe8\x5a\xa3\xe2\xce\xbe\xfa\x3c\xcf\xd2\x74\x78\x90\x64\xce\x47\x85\xfc\x33\x3c\x31\x82\x8e\x4c\x11\x2a\x30\x26\xf8\x57\x58\x83\xc2\x1d\xd9\x7d\x39\x72\xa2\x39\x8a\xd7\x3e\x0a\x57\xad\xe1\x99\xb4\xbf\xb1\x8a\x59\xea\xa7\x78\xb1\xe2\xc0\xc5\x06\x3e\x57\xfe\x14\x5e\x43\xdf\x9f\xed\xf1\xf8\x9d\x33\x6d\xe5\xde\xc7\xcf\x87\xae\x83\x0d\xb3\x15\x93\xe1\x96\x07\xd9\x0b\xaa\xdb\x98\x7a\x25\xa4\x5f\xc6\xf2\x9e\x1c\xd5\x8d\x2b\x6f\xbc\xeb\xf5\x49\x98\x9c\x76\x04\x72\x01\x42\x51\x96\x47\x19\xa4\x64\x1f\x78\x99\x2e\xe0\xd5\xf7\xe2\x6c\x3f\xe6\x79\x9e\x65\xbd\xbf\xe0\x63\x9f\xa9\x34\x9e\x33\xce\x85\x7f\xf6\x99\x4c\xdf\xab\xfb\xb4\xfb\x6e\xa7\x42\x4c\x52\x31\xe5\xc7\x43\xbd\x45\x63\x04\xe7\xa8\xfc\x80\xa8\x0d\x7d\xcc\x6b\x1a\x81\x77\x98\xe1\xab\x3f\xd5\x08\xf1\x59\xa4\xdb\x72\xe0\xea\xf1\xc7\xf9\xc4\x9d\xf1\xf4\xf4\x5f\x00\x00\x00\xff\xff\x01\xb7\xd2\x45\x89\x10\x00\x00") func templateMetaTmplBytes() ([]byte, error) { return bindataRead( @@ -981,7 +981,7 @@ func templateMetaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/meta.tmpl", size: 4293, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/meta.tmpl", size: 4233, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/meta.tmpl b/entc/gen/template/meta.tmpl index cb65318ee..159a4268d 100644 --- a/entc/gen/template/meta.tmpl +++ b/entc/gen/template/meta.tmpl @@ -81,52 +81,50 @@ const ( {{ end }} {{/* define custom type for enum fields */}} -{{ range $f := $.Fields -}} - {{ if $f.IsEnum }} - {{/* omit the package name from the type. */}} - {{ $enum := trimPackage $f.Type.String $.Package }} - // {{ $enum }} defines the type for the {{ $f.Name }} enum field. - type {{ $enum }} string +{{ range $f := $.EnumFields -}} + {{/* omit the package name from the type. */}} + {{ $enum := trimPackage $f.Type.String $.Package }} + // {{ $enum }} defines the type for the {{ $f.Name }} enum field. + type {{ $enum }} string - {{- if $f.Default }} - {{- /* find the enum that holds the default value. */ -}} - {{- range $_, $e := $f.Enums }} - {{- if eq $e $f.DefaultValue }} - {{- $name := $f.EnumName $e }} - // {{ $name }} is the default {{ $enum }}. - const {{ $f.DefaultName }} = {{ $name }} - {{- end }} + {{- if $f.Default }} + {{- /* find the enum that holds the default value. */ -}} + {{- range $_, $e := $f.Enums }} + {{- if eq $e $f.DefaultValue }} + {{- $name := $f.EnumName $e }} + // {{ $name }} is the default {{ $enum }}. + const {{ $f.DefaultName }} = {{ $name }} {{- end }} {{- end }} + {{- end }} - // {{ $enum }} values. - const ( - {{- range $_, $e := $f.Enums }} - {{ $f.EnumName $e }} {{ $enum }} = "{{ $e }}" - {{- end }} - ) + // {{ $enum }} values. + const ( + {{- range $_, $e := $f.Enums }} + {{ $f.EnumName $e }} {{ $enum }} = "{{ $e }}" + {{- end }} + ) - {{ $receiver := receiver $f.BuilderField -}} - func ({{ $receiver }} {{ $enum }}) String() string { - return string({{ $receiver }}) + {{ $receiver := receiver $f.BuilderField -}} + func ({{ $receiver }} {{ $enum }}) String() string { + return string({{ $receiver }}) + } + + {{ $name := $f.Validator -}} + // {{ $name }} is a validator for the "{{ $receiver }}" field enum values. It is called by the builders before save. + func {{ $name }}({{ $receiver }} {{ $enum }}) error { + switch {{ $receiver }} { + case {{ range $i, $e := $f.Enums }}{{ if ne $i 0 }},{{ end }}{{ $f.StructField }}{{ pascal $e }}{{ end }}: + return nil + default: + return fmt.Errorf("{{ $.Package }}: invalid enum value for {{ $f.Name }} field: %q", {{ $receiver }}) } - - {{ $name := $f.Validator -}} - // {{ $name }} is a validator for the "{{ $receiver }}" field enum values. It is called by the builders before save. - func {{ $name }}({{ $receiver }} {{ $enum }}) error { - switch {{ $receiver }} { - case {{ range $i, $e := $f.Enums }}{{ if ne $i 0 }},{{ end }}{{ $f.StructField }}{{ pascal $e }}{{ end }}: - return nil - default: - return fmt.Errorf("{{ $.Package }}: invalid enum value for {{ $f.Name }} field: %q", {{ $receiver }}) - } - } - {{ end }} + } {{ end }} {{ template "meta/additional" $ }} {{ end }} -{{/* A template that can be overrided in order to add additional code for the type package. */}} +{{/* A template that can be overridden in order to add additional code for the type package. */}} {{ define "meta/additional" }}{{ end }} diff --git a/entc/gen/type.go b/entc/gen/type.go index 0c008a912..bdd2ba454 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -367,6 +367,17 @@ func (t Type) MutableFields() []*Field { return fields } +// EnumFields returns the types's enum fields. +func (t Type) EnumFields() []*Field { + var fields []*Field + for _, f := range t.Fields { + if f.IsEnum() { + fields = append(fields, f) + } + } + return fields +} + // NumM2M returns the type's many-to-many edge count func (t Type) NumM2M() int { var n int