diff --git a/entc/gen/bindata.go b/entc/gen/bindata.go index 300562f6a..73937c871 100644 --- a/entc/gen/bindata.go +++ b/entc/gen/bindata.go @@ -124,7 +124,7 @@ func templateBaseTmpl() (*asset, error) { return a, nil } -var _templateBuilderCreateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x56\x5d\x6f\xa4\x36\x14\x7d\x66\x7e\xc5\x5d\xc4\x56\x43\x94\x30\xdd\xd7\xa9\xd2\x87\x6e\xb6\x6a\x5f\xb6\x95\xd2\x56\x2b\x75\xab\xca\x81\x0b\xe3\xc6\x63\x58\xdb\x90\x89\x10\xff\xbd\xba\xb6\x01\x43\x3e\x3a\xdb\xa7\x41\x1e\xfb\xdc\xe3\x73\x8e\xaf\xdd\xf7\x50\x60\xc9\x25\x42\x9c\x2b\x64\x06\x63\x18\x86\x4d\xdf\x43\xd2\xdc\x57\xb0\xbf\x86\x3b\xa6\x11\x92\xec\x7d\x2d\x4b\x5e\x65\xbf\xb2\xfc\x9e\x55\x48\x73\x68\x92\xc1\x63\x23\x98\x41\x88\x0f\xc8\x0a\x54\x31\x24\x4f\xff\xe2\xc7\xa6\x56\x26\xf8\x2b\xb9\x6b\xb9\x28\x50\x11\x7c\xa3\xb8\x34\xb0\x6d\x98\xce\x99\x80\x24\xfb\xc8\x8e\x98\x42\xfc\x7e\xc9\x45\x61\x8e\xbc\x73\x2b\xa6\xef\x09\x86\x60\x77\x3b\x08\x91\x87\x01\xb8\x06\x73\x40\x18\x47\xca\x5a\x81\xdd\x21\x97\x15\x30\x3b\xd9\x16\xa3\xa9\x28\x0d\x37\x8f\xd9\xc6\x3c\x36\xb8\x86\xd1\x46\xb5\xb9\x81\x7e\x13\xe5\x56\x82\x4d\xd4\xf7\xa0\x98\xac\x10\x92\xbf\x2f\x21\x29\x89\x53\x92\xfd\xc8\x51\x14\x9a\xa8\x44\x51\xdf\x5f\x41\x52\x66\xb7\x76\xa5\xfd\x83\x80\x2e\x08\xb8\xcc\x7e\xa3\x1a\x34\xad\xef\x01\x65\xe1\x3f\xaf\x42\x48\x74\x90\x1f\x8a\x0a\x43\x44\x5c\x23\x1e\x59\xf3\xa7\xdd\xc7\xcf\x37\x23\xec\x5f\x8e\x6e\x3f\xe3\x5f\x0d\xc3\xc6\xc9\xfe\xc0\xcd\x01\xf0\x64\x68\x34\x81\xf8\x07\xb7\xc7\x78\xa1\x63\xb4\x70\x4e\xa3\x31\x34\x23\xf3\x3e\x78\xbe\x24\xf6\x2d\xeb\xd0\xe9\x89\x4e\xe7\x85\xa0\x5c\xda\xb1\x82\x19\x46\xf9\xc9\x36\x65\x2b\x73\xd8\x2e\xac\x1c\x25\x99\xab\xa7\x16\x75\x9b\x9b\x13\xe4\xb5\x34\x78\x32\x14\x3b\xfa\x4d\x61\x7b\x11\x16\xb8\x04\x54\xaa\x56\x29\xd9\xf2\x9a\x1d\x57\x93\x7a\xbc\x84\x5a\x91\xfe\x3f\x31\x7d\x83\x25\x6b\x85\x81\xad\xac\x0d\x0d\xfd\xd2\x18\x5e\x4b\x26\x52\x3f\x3f\xe2\x25\xac\xa8\x66\xce\xbc\x95\x01\xd7\xd7\x20\xb9\x20\x12\x11\x55\xa1\x22\xcb\x0a\x1e\x2f\x8a\x3a\xa2\x65\x77\x30\x9f\x20\x8f\xe9\xe7\xbe\xaf\xa5\x36\x4c\x1a\x18\x97\x9c\xc7\x00\xbe\xe9\xc6\xea\x28\x34\xce\x15\x15\x9a\x56\x49\xe2\xe7\xc5\xd2\xd9\x47\x7c\xd8\xc6\xe3\xd1\x1e\x86\x3d\x1c\xb9\xd6\x74\x1c\x14\x7e\x69\xb9\xc2\x02\x4a\x8b\xfb\x39\x76\xb5\xbc\xd8\x9f\xe3\x38\x9d\x6a\xf8\x44\x45\x51\xe4\x94\x0d\x46\xc6\x88\x25\x65\xf6\x07\x13\xbc\x60\xa6\x56\xa3\x05\x51\xdf\xef\x2e\x80\x15\x05\xc8\x56\x08\x76\x27\x10\xf2\x03\xe6\xf7\x50\x4b\xf1\x68\xcf\x66\xed\x4d\x70\x1c\xb4\x85\xaa\x5b\x43\xdd\xc9\x4a\xd9\x31\xd1\x22\x5c\xec\x66\x40\x48\x26\xac\xfd\x35\x30\x4a\xf5\xec\xe5\x64\xee\xec\x46\x3a\x2f\xb5\x79\x98\x97\x53\x62\xcf\xb4\xfc\x8d\xb7\x1c\x96\x62\x50\x64\x50\xa9\x97\x5d\x9e\x14\x81\x61\x70\x59\xfe\xaf\x52\xe9\x77\x16\xf1\x4d\x98\xb1\x85\xab\xe5\xd1\x64\x1f\xc8\xd9\x72\xe9\x6a\x37\x95\x2a\x19\x17\xe4\x2a\x7d\x3e\xef\xec\x1e\xde\x76\xb1\x0d\x88\xb3\xf8\x45\x7d\x06\x08\xfa\xd5\xc2\xf7\xe5\xf7\x19\x8d\x8c\xa0\x31\xfb\x5d\xf2\x2f\x2d\x06\x27\x4e\xa0\x5c\x37\x08\xab\xcb\xba\xed\xa5\xf0\x3d\xbc\xf3\x7a\x9c\x15\xf2\x56\x18\xde\x08\x04\xa6\x35\xaf\xe4\x11\xa5\xd1\x50\x4b\x60\xd0\x3a\x0a\x58\x54\xe8\x95\xc1\x75\xe6\x9f\x09\xb9\xdd\x80\x0d\x17\xce\x69\x7b\xbd\x71\x3c\xe9\xdc\x8b\xc6\xf1\xbf\x4e\xea\xd7\x90\x5e\x3b\xc4\x4b\xa8\x0c\x6c\x05\x4a\x48\xb2\x5b\x53\x2b\x56\x61\x0a\xef\xfc\x26\xf4\x03\x37\xf9\xe1\xc9\x3e\x0a\x45\x5f\xd9\x0d\x67\x02\x73\xb3\xb5\xad\x77\xed\xb7\x76\x58\xce\x75\x0f\xec\x7c\xcf\xe9\x15\xd1\xf7\xf0\x4f\xcd\xe5\x34\x6f\x04\xd3\x10\x5f\x02\xdd\xf5\xfb\xcd\x2c\xc7\x73\x3a\xea\x09\x72\xbc\x28\x52\x4f\x62\x4a\xa6\x6f\x17\x21\xd2\xab\xc2\xb6\x52\xb7\x0d\xbd\x4f\xb0\x80\xc2\xd1\xb1\x22\x7a\xa9\x82\x9e\xfa\x32\x2f\x2e\x0b\x3c\x05\x3b\xfe\x76\x49\x30\xe0\x37\xdf\x9d\x9f\x20\x67\x42\x68\x77\x8f\x52\xef\x6a\x98\xe4\xb9\x26\x6f\xec\x90\xab\xa6\x81\x49\x47\xfd\xab\xae\xd0\x4f\xcf\xdf\xa1\x8b\x2b\x94\xfc\xeb\x2e\xc3\xa6\x15\xee\x2a\xa0\xef\x3b\x5b\xd0\x87\x2c\xd5\xad\xeb\x19\xc3\x66\x14\xa6\x73\xcf\x8c\xf3\x02\x71\xee\x73\xc4\xb6\x79\x73\x6c\xc4\xf4\x56\x2c\x21\xf6\x3e\xed\xde\xea\xdd\xf8\x66\x0d\xa2\xe1\x16\x9d\xa6\x57\x8c\x5b\x9e\xad\xde\x5c\xc1\x6b\x66\xfe\xfc\x37\x00\x00\xff\xff\x04\x4e\x37\x66\x0d\x0b\x00\x00") +var _templateBuilderCreateTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x56\x5f\x8f\x9c\xb6\x17\x7d\x66\x3e\xc5\x0d\x22\x3f\xc1\x6a\x97\xf9\xe5\x75\xaa\xed\x43\xb3\xa9\x9a\x97\xb4\xd2\xa6\x55\xa4\xa6\xaa\xbc\x70\x61\xdc\xf5\x18\x62\x9b\xd9\x59\x21\xbe\x7b\x75\x6d\x03\x86\xfd\xa3\x49\x9f\x06\x79\xec\x73\x8f\xcf\x39\xbe\x76\xdf\x43\x89\x15\x97\x08\x71\xa1\x90\x19\x8c\x61\x18\x36\x7d\x0f\x49\x7b\x5f\xc3\xee\x1a\xee\x98\x46\x48\xf2\xf7\x8d\xac\x78\x9d\xff\xc6\x8a\x7b\x56\x23\xcd\xa1\x49\x06\x0f\xad\x60\x06\x21\xde\x23\x2b\x51\xc5\x90\x3c\xfd\x8b\x1f\xda\x46\x99\xe0\xaf\xe4\xae\xe3\xa2\x44\x45\xf0\xad\xe2\xd2\x40\xda\x32\x5d\x30\x01\x49\xfe\x89\x1d\x30\x83\xf8\xfd\x92\x8b\xc2\x02\xf9\xd1\xad\x98\xbe\x27\x18\x82\xdd\x6e\x21\x44\x1e\x06\xe0\x1a\xcc\x1e\x61\x1c\xa9\x1a\x05\x76\x87\x5c\xd6\xc0\xec\x64\x5b\x8c\xa6\xa2\x34\xdc\x3c\xe6\x1b\xf3\xd8\xe2\x1a\x46\x1b\xd5\x15\x06\xfa\x4d\x54\x58\x09\x36\x51\xdf\x83\x62\xb2\x46\x48\xfe\xbe\x84\xa4\x22\x4e\x49\xfe\x33\x47\x51\x6a\xa2\x12\x45\x7d\x7f\x05\x49\x95\xdf\xda\x95\xf6\x0f\x02\xba\x20\xe0\x2a\xff\x4c\x35\x68\x5a\xdf\x03\xca\xd2\x7f\x5e\x85\x90\xe8\x20\x3f\x94\x35\x86\x88\xb8\x46\x3c\xb0\xf6\x4f\xbb\x8f\x8f\x37\x23\xec\x5f\x8e\x6e\x3f\xe3\x5f\x0d\xc3\xc6\xc9\xfe\xc0\xcd\x1e\xf0\x64\x68\x34\x81\xf8\x27\xb7\xc7\x78\xa1\x63\xb4\x70\x4e\xa3\x31\x34\x23\xf7\x3e\x78\xbe\x24\xf6\x2d\x3b\xa2\xd3\x13\x9d\xce\x0b\x41\xb9\xb4\x63\x25\x33\x8c\xf2\x93\x6f\xaa\x4e\x16\x90\x2e\xac\x1c\x25\x99\xab\x67\x16\x35\x2d\xcc\x09\x8a\x46\x1a\x3c\x19\x8a\x1d\xfd\x66\x90\x5e\x84\x05\x2e\x01\x95\x6a\x54\x46\xb6\xbc\x66\xc7\xd5\xa4\x1e\xaf\xa0\x51\xa4\xff\x2f\x4c\xdf\x60\xc5\x3a\x61\x20\x95\x8d\xa1\xa1\x5f\x5b\xc3\x1b\xc9\x44\xe6\xe7\x47\xbc\x82\x15\xd5\xdc\x99\xb7\x32\xe0\xfa\x1a\x24\x17\x44\x22\xa2\x2a\x54\x64\x59\xc1\xe3\x45\xd1\x91\x68\xd9\x1d\xcc\x27\xc8\x63\xfa\xb9\x7e\x67\x13\xca\x47\xfd\x99\xdb\x91\x34\x0b\x92\xe2\x0b\x9d\x41\x0d\xfe\x77\x1c\x69\xa1\xd0\x38\x53\x51\x68\x3a\x25\x89\xb8\x57\x51\xe7\x9f\xf0\x21\x8d\xc7\x33\x3f\x0c\x3b\x38\x70\xad\xe9\x9c\x28\xfc\xd6\x71\x85\x25\x54\x16\xf7\x6b\xec\x6a\x79\xae\x5f\xe3\x38\x9b\x6a\xf8\xa8\x45\x51\xe4\x24\x0f\x46\xc6\xec\x25\x55\xfe\x07\x13\xbc\x64\xa6\x51\xa3\x37\x51\xdf\x6f\x2f\x80\x95\x25\xc8\x4e\x08\x76\x27\x10\x8a\x3d\x16\xf7\xd0\x48\xf1\x68\x0f\x6d\xe3\xdd\x71\x1c\xb4\x85\x6a\x3a\x43\x6d\xcb\x6a\x7c\x64\xa2\x43\xb8\xd8\xce\x80\x90\x4c\x58\xbb\x6b\x60\x14\xf7\xd9\xe4\xc9\xf5\xd9\xa6\x6c\x5e\x6a\x83\x32\x2f\xa7\x28\x9f\x99\x85\x37\x3e\x0b\xb0\x14\x83\xb2\x84\x4a\xbd\x6c\xff\xa4\x08\x59\x7d\x71\x4e\xa9\xec\x07\x8b\xf8\x26\x0c\xdf\xc2\xd5\xea\x60\xf2\x0f\xe4\x6c\xb5\x74\xf5\x38\x95\xaa\x18\x17\xe4\x2a\x7d\x3e\xef\xec\x0e\xde\x1e\x63\x1b\x10\x67\xf1\x8b\xfa\x0c\x10\xc6\x33\xdc\xfc\xf2\xfb\x8c\x0e\x47\xd0\x98\xff\x2e\xf9\xb7\x0e\x83\xa3\x28\x50\xae\x3b\x87\xd5\x65\xdd\x0f\x33\xf8\x11\xde\x79\x3d\xce\x0a\x79\x27\x0c\x6f\x05\x02\xd3\x9a\xd7\xf2\x80\xd2\x68\x68\x24\x30\xe8\x1c\x05\x2c\x6b\xf4\xca\xe0\x3a\xf3\xcf\x84\xdc\x6e\xc0\x86\x0b\xe7\xb4\xbd\xde\x51\x9e\xb4\xf4\x45\x47\xf9\x4f\x27\xf5\x7b\x48\xaf\x1d\xe2\x15\xd4\x06\x52\x81\x12\x92\xfc\xd6\x34\x8a\xd5\x98\xc1\x3b\xbf\x09\xfd\xc0\x4d\xb1\x7f\xb2\x8f\x52\xd1\x57\x7e\xc3\x99\xc0\xc2\xa4\xb6\x27\xaf\xfd\xd6\x0e\xcb\xb9\xee\x81\x9d\xef\x05\x3d\x2f\xfa\x1e\xfe\x69\xb8\x9c\xe6\x8d\x60\x1a\xe2\x4b\xa0\x47\xc0\x6e\x33\xcb\xf1\x9c\x8e\x7a\x82\x1c\x6f\x90\xcc\x93\x98\x92\xe9\xdb\x45\x88\xf4\xaa\xb0\x9d\xd4\x5d\x4b\x0f\x17\x2c\xa1\x74\x74\xac\x88\x5e\xaa\xa0\xa7\xbe\xcc\x8b\xcb\x12\x4f\xc1\x8e\xff\xbf\x24\x18\xf0\x9b\x2f\xd5\x2f\x50\x30\x21\xb4\xbb\x60\xa9\x77\xb5\x4c\xf2\x42\x93\x37\x76\xc8\x55\xd3\xc0\xa4\xa3\xfe\x5d\x77\xeb\x97\xe7\x2f\xd7\xc5\xdd\x4a\xfe\x1d\x2f\xc3\xa6\x15\xee\x2a\xa0\xef\x3b\x5b\xd0\x87\x2c\xd5\xd4\xf5\x8c\x61\x33\x0a\x73\x74\xef\x8f\xf3\x02\x71\xee\x3b\xc5\xb6\x79\x73\x68\xc5\xf4\x88\xac\x20\xf6\x3e\x6d\xdf\xea\xed\xf8\x98\x0d\xa2\xe1\x16\x9d\xa6\xe7\x8d\x5b\x9e\xaf\x1e\x63\xc1\x33\x67\xfe\xfc\x37\x00\x00\xff\xff\x1e\xd5\x2d\x22\x26\x0b\x00\x00") func templateBuilderCreateTmplBytes() ([]byte, error) { return bindataRead( @@ -139,7 +139,7 @@ func templateBuilderCreateTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/builder/create.tmpl", size: 2829, mode: os.FileMode(420), modTime: time.Unix(1565106398, 0)} + info := bindataFileInfo{name: "template/builder/create.tmpl", size: 2854, mode: os.FileMode(420), modTime: time.Unix(1566207999, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -764,7 +764,7 @@ func templateImportTmpl() (*asset, error) { return a, nil } -var _templateMetaTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x54\x4d\x6f\xe3\x36\x10\x3d\xcb\xbf\x62\x2a\x68\x01\x09\x70\xe4\xf6\x9a\xc2\xa7\x2e\x8a\x2e\x50\x14\x05\xba\xc8\x25\x08\x02\x5a\x1a\xc6\x4c\x68\xca\x25\x69\xc7\x01\xc1\xff\x5e\x0c\x3f\x64\xc9\x75\x36\x39\xd9\xe4\xcc\xbc\x79\x6f\xe6\x89\xce\x41\x8f\x5c\x28\x84\x72\x87\x96\x95\xe0\xfd\x62\xe1\xdc\x0d\xbc\x0a\xbb\x05\x3c\x59\x54\x3d\x54\x50\xfe\xcd\xba\x17\xf6\x84\x25\x54\x6d\xfa\x0b\x37\xde\x2f\x0a\xe7\xc0\xe2\x6e\x2f\x99\x45\x28\xb7\xc8\x7a\xd4\x25\xb4\x84\xe2\x1c\x50\x6d\xc4\x9b\x24\x89\xdd\x7e\xd0\xb6\x84\x2a\x84\xba\x41\x19\x0b\xf5\xa2\x58\xad\xe0\x4f\xb6\x41\x09\xdb\x41\xf6\x06\xec\x16\xc1\x58\x2d\xd4\x13\xc8\x70\xdd\xa3\x1a\x2c\x1d\x29\xe2\x1c\xc8\xe1\x15\x35\x54\xed\x5f\x6c\x87\xe0\x3d\xd8\xb7\x3d\x82\x50\x21\xdc\x33\xcb\x36\xcc\x60\xbb\x28\x22\xe6\x1a\x4a\xe7\xa0\x6a\xe3\xc9\xfb\x32\xf4\x0b\x57\xdf\xbe\xb6\xbf\x11\x07\xa6\x2c\xc1\xfc\xaf\xfb\xac\xaf\xe8\x81\x0b\x94\xfd\x95\x46\xd7\xc0\x62\x5b\xa3\xd8\x0b\xc6\x60\x22\x5b\x86\x74\xcd\xd4\x13\x42\xf5\xb8\x84\x8a\xc3\xed\x1a\xaa\xf6\x77\xc2\x36\x34\x58\x42\x8b\x9d\x28\xc0\xcf\xa8\x61\xe8\x99\x7c\xcc\xf8\x90\xf5\x79\x5a\x7c\x1c\xd7\x11\xb5\xc5\x13\xec\xf5\xb0\x47\x6d\xdf\xae\x08\x2a\x66\x1d\x66\x52\xf8\x5c\x08\xad\x39\x9b\x61\x22\xca\xd8\x41\x93\x4f\x82\xb4\x7f\xd2\x21\xd0\x27\x64\xbb\xdb\x4b\x0a\xed\xb5\x50\x96\x43\xd9\x0b\x26\xb1\xb3\xab\x2f\x66\x45\x46\x5c\x75\x49\xb1\x29\xcf\x48\xb9\xf8\x34\xba\x29\xc2\x04\x2b\x15\x67\xc3\x35\xc1\x72\x9f\xa1\xf2\x19\x26\x47\xa6\x05\xdb\x48\xbc\x64\xe2\x1c\x08\x0e\x5b\x66\xbe\xcf\xd9\x7c\x96\xe5\xfc\x03\x11\x1c\x06\xf2\xf3\x1f\xcc\x7c\x45\xce\x0e\xd2\xc6\xc3\x1d\x93\xa2\x67\x76\xd0\x86\x32\x8f\x4c\xd3\xc7\xc2\xa3\x51\xd6\xb4\x5a\x5a\x17\xa9\xea\xb6\xb8\x63\xe0\x7d\x1b\x9c\x98\x16\xe4\x7c\x32\x55\xdd\x4c\xd7\x23\xae\x79\x2e\xb2\x16\x9c\xf6\x3b\x61\x11\x02\x05\x3d\x09\x55\x9f\xae\xa2\x27\x53\xc2\x85\x35\xb3\x37\xfb\xb1\x7c\xe2\xce\x7c\x79\x64\xf2\x80\xc0\x07\x9d\xfd\x39\x71\x66\xd0\xd6\xc6\x9e\x33\x98\x75\x0c\x99\x7b\xba\x17\xe0\xfd\x43\x7b\x47\x38\x75\xd3\xd6\x11\xe2\x3b\xbd\x01\xde\x37\x51\xc9\x68\x4b\x3a\x84\xe7\xac\xe2\xed\x64\x9c\x37\x59\x19\x54\x8a\x7a\x47\x55\x63\xc2\x34\x1e\x1e\x97\xdb\x35\x8c\x1e\xe1\x07\xd5\x41\xfd\xc5\x34\x80\x5a\x0f\xba\x1c\xbb\xcf\x87\xa0\x92\x26\x61\x80\x91\xe8\x84\x9c\x85\x97\x33\xe5\x65\x92\x0e\xdf\x2c\x15\x74\x4c\x4a\xec\x61\xf3\x16\x52\x37\x07\x21\x7b\xd4\x06\x36\xc8\x07\x8d\x60\xd8\x11\xf3\x90\x04\x07\xfc\xf7\x42\xdc\x2f\x99\x49\x31\xe5\x71\x7d\x84\xa9\xa6\x6e\xee\x7f\x7e\x88\xa3\xb4\xe7\x41\x86\x49\x4a\x83\xef\xe1\x1d\x54\x57\x37\x30\x29\x02\x17\xd2\x8a\xe3\x99\xcc\xed\x07\x7d\x63\x01\x57\x21\xf3\xbe\x6d\xdb\x87\x00\x3b\x5f\x6a\x9c\x74\x46\x0f\x86\x4c\x6e\x7e\x5e\x42\xa5\xa8\xf4\x94\x2e\x66\x93\x48\xb4\x67\x8c\x02\x8f\xe7\xc0\xa3\x7e\xb7\x55\xb3\x9c\xb4\x4a\x5f\x6a\x38\xa7\x1f\x8d\xf6\xa0\x15\x4c\xea\xb3\x85\x7f\x48\x9c\x96\xff\xb8\x04\x1e\x18\x47\xc2\xa4\x3c\x87\x0b\xda\xa6\xd6\x61\x66\x6a\x8e\xdb\xfc\x1a\x22\x3f\xad\x41\x09\x79\x2e\xc8\x44\x50\xeb\x7c\x95\x25\xe7\xdf\x94\xa1\x84\x9c\x2a\xf0\xf5\xb8\xe0\xe9\xa7\x32\x7d\xce\xf3\xff\xe6\xe2\xb5\x8a\x7f\xff\x0b\x00\x00\xff\xff\x04\x51\xec\xbb\x3d\x08\x00\x00") +var _templateMetaTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x54\x5d\x6b\xeb\x38\x10\x7d\x76\x7e\xc5\xac\x71\xc1\x86\xd4\xd9\x7d\xed\x92\xa7\x2d\xcb\x16\x96\x65\xe1\x96\xbe\x94\x52\x94\x78\xd4\xa8\x55\xe4\x5c\x49\x49\x53\x84\xfe\xfb\x65\xf4\xe1\xd8\xbd\xe9\x6d\x9f\x12\x69\x66\xce\x9c\x39\x73\x2c\xe7\xa0\x43\x2e\x14\x42\xb9\x45\xcb\x4a\xf0\x7e\x36\x73\xee\x12\x5e\x85\xdd\x00\x1e\x2d\xaa\x0e\x2a\x28\xff\x67\xeb\x17\xf6\x84\x25\x54\x6d\xfa\x0b\x97\xde\xcf\x0a\xe7\xc0\xe2\x76\x27\x99\x45\x28\x37\xc8\x3a\xd4\x25\xb4\x84\xe2\x1c\x50\x6d\xc4\x1b\x25\x89\xed\xae\xd7\xb6\x84\x2a\x84\xd6\xbd\x32\x16\xea\x59\xb1\x58\xc0\xbf\x6c\x85\x12\x36\xbd\xec\x0c\xd8\x0d\x82\xb1\x5a\xa8\x27\x90\xe1\xba\x43\xd5\x5b\x3a\x52\xc4\x39\x90\xfd\x2b\x6a\xa8\xda\xff\xd8\x16\xc1\x7b\xb0\x6f\x3b\x04\xa1\x42\xb8\x63\x96\xad\x98\xc1\x76\x56\x44\xcc\x25\x94\xce\x41\xd5\xc6\x93\xf7\x65\xe8\x17\xae\x6e\xae\xdb\xbf\x88\x03\x53\x96\x60\x7e\xea\x3e\xe9\x2b\x3a\xe0\x02\x65\x77\xa6\xd1\x39\xb0\xd8\xd6\x28\xf6\x82\x31\x98\xc8\x96\x21\x5d\x33\xf5\x84\x50\x3d\xce\xa1\xe2\x70\xb5\x84\xaa\xfd\x9b\xb0\x0d\x09\x4b\x68\xb1\x13\x05\xf8\x09\x35\x88\x9e\xc9\xc7\x8c\x4f\x59\x9f\xd4\xe2\x83\x5c\x07\xd4\x16\x8f\xb0\xd3\xfd\x0e\xb5\x7d\x3b\x33\x50\x31\xe9\x30\x19\x85\x4f\x07\xa1\x35\x67\x33\x8c\x86\x32\xb6\xd7\xe4\x93\x30\xda\xb7\x74\x08\xf4\x09\xd9\x6e\x77\x92\x42\x3b\x2d\x94\xe5\x50\x76\x82\x49\x5c\xdb\xc5\x85\x59\x90\x11\x17\xeb\x34\xb1\x29\x4f\x48\xb9\xf8\x38\xb8\x29\xc2\x04\x2b\x15\x27\xc3\x35\xc1\x72\x5f\xa1\xf2\x15\x26\x07\xa6\x05\x5b\x49\x7c\xcf\xc4\x39\x10\x1c\x36\xcc\xdc\x4e\xd9\x7c\x95\xe5\xf4\x03\x11\x1c\x7a\xf2\xf3\x3f\xcc\x5c\x23\x67\x7b\x69\xe3\xe1\x8e\x49\xd1\x31\xdb\x6b\x43\x99\x07\xa6\xe9\x63\xe1\xd1\x28\x4b\x5a\x2d\xad\x8b\xa6\x5a\x6f\x70\xcb\xc0\xfb\x36\x38\x31\x2d\xc8\xf9\x64\xaa\xba\x19\xaf\x47\x9c\xf3\x5c\x64\x2d\x38\xed\x77\xc4\x22\x04\x0a\x7a\x12\xaa\x2e\x5d\x45\x4f\xa6\x84\xd0\x29\x96\x67\x5f\x76\x43\xe9\xc8\x99\xf9\xf2\xc0\xe4\x1e\x81\xf7\x3a\x7b\x73\xe4\xca\x30\x57\x1b\xfb\x4d\x60\x96\x31\x64\xee\xe9\x5e\x80\xf7\x0f\xed\x1d\xe1\xd4\x4d\x5b\x0f\xa4\x6f\xcc\xad\x08\x38\x7c\xaf\xd6\x75\x03\x83\xc0\xb1\xc9\x2d\xbd\x10\xde\x37\x71\xce\xc1\xb4\x74\x08\x8f\x5d\xc5\xdb\x91\xd8\x97\x79\x6e\xa8\x14\xb1\x8b\x33\x0f\x09\xe3\x78\x78\x7a\xae\x96\x30\x38\x88\xfa\x43\x7d\x61\x1a\x40\xad\x7b\x5d\x0e\xdd\xa7\x32\xa9\x34\xb5\x30\xc0\x48\x96\x84\x9c\xa5\x29\x27\xda\x94\x49\x1c\xb8\xb1\x54\xb0\x66\x52\x62\x07\xab\xb7\x90\xba\xda\x0b\xd9\xa1\x36\xb0\x42\xde\x6b\x04\xc3\x0e\x98\x65\x14\x1c\xf0\xfb\xbb\xe1\xfe\xc8\x4c\x8a\x31\x8f\xf3\x22\xa7\x9a\xba\xb9\xff\xfd\x21\x88\x1d\xe7\x8d\x42\x06\x25\xa5\xc1\x8f\xf0\x86\x45\xe4\x22\x70\x21\xad\x38\x9c\xc8\x5c\x7d\xd2\x37\x16\x70\x15\x32\xef\xdb\xb6\x7d\x08\xb0\xd3\xa5\x46\xa5\x33\x7a\xb0\x6b\xf2\xfa\xf3\x1c\x2a\x45\xa5\xc7\x74\x31\x51\x22\xd1\x9e\x30\x0a\x3c\x9e\x03\x8f\xfa\xc3\x56\xcd\x7c\xd4\x2a\x7d\xc7\xe1\x9c\x7e\x34\xda\xbd\x56\x30\xaa\xcf\x26\xff\x25\x71\x5a\xfe\xe3\x1c\x78\x60\x1c\x09\xd3\xe4\x39\x5c\xd0\x36\xb5\x0e\x9a\xa9\x29\x6e\xf3\x67\x88\xfc\xb6\x04\x25\xe4\xa9\x20\x13\x41\xad\xf3\x55\x1e\x39\xff\xa6\x0c\x25\xe4\x78\x02\x5f\x0f\x0b\x1e\x7f\x2a\xe3\xc7\x3e\xff\x6f\xde\xbd\x65\xf1\xef\x8f\x00\x00\x00\xff\xff\xab\xe1\xd9\x49\x5b\x08\x00\x00") func templateMetaTmplBytes() ([]byte, error) { return bindataRead( @@ -779,7 +779,7 @@ func templateMetaTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/meta.tmpl", size: 2109, mode: os.FileMode(420), modTime: time.Unix(1565553921, 0)} + info := bindataFileInfo{name: "template/meta.tmpl", size: 2139, mode: os.FileMode(420), modTime: time.Unix(1566208043, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/builder/create.tmpl b/entc/gen/template/builder/create.tmpl index b4acd785c..732ee580b 100644 --- a/entc/gen/template/builder/create.tmpl +++ b/entc/gen/template/builder/create.tmpl @@ -29,7 +29,7 @@ func ({{ $receiver }} *{{ $builder }}) Save(ctx context.Context) (*{{ $.Name }}, {{- if or $f.HasDefault (not $f.Optional) -}} if {{ $receiver }}.{{ $f.StructField }} == nil { {{ if $f.HasDefault -}} - v := {{ $.Package }}.{{ $f.DefaultConstant }} + v := {{ $.Package }}.{{ $f.DefaultName }}{{ if $f.IsTime }}(){{ end }} {{ $receiver }}.{{ $f.StructField }} = &v {{ else -}} return nil, errors.New("{{ $pkg }}: missing required field \"{{ $f.Name }}\"") diff --git a/entc/gen/template/meta.tmpl b/entc/gen/template/meta.tmpl index ee7c7a9c7..4cc84c265 100644 --- a/entc/gen/template/meta.tmpl +++ b/entc/gen/template/meta.tmpl @@ -33,9 +33,9 @@ var ( fields = {{ base $.Schema }}.{{ $.Name }}{}.Fields() {{ range $i, $f := $.Fields -}} {{ if $f.HasDefault }} - {{- $default := $f.DefaultConstant -}} + {{- $default := $f.DefaultName -}} // {{ $default }} holds the default value for the {{ $f.Name }} field. - {{ $default }} = fields[{{ $i }}].Value().({{ $f.Type }}) + {{ $default }} = fields[{{ $i }}].Value().({{ if $f.IsTime }}func() {{ end }}{{ $f.Type }}) {{ end -}} {{ with $f.Validators -}} {{ $name := $f.Validator -}} diff --git a/entc/gen/type.go b/entc/gen/type.go index 881dd2b58..c2aa603a1 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -308,8 +308,8 @@ func (t *Type) AddIndex(idx *load.Index) error { // Constant returns the constant name of the field. func (f Field) Constant() string { return "Field" + pascal(f.Name) } -// DefaultConstant returns the constant name of the default value of this field. -func (f Field) DefaultConstant() string { return "Default" + pascal(f.Name) } +// DefaultName returns the variable name of the default value of this field. +func (f Field) DefaultName() string { return "Default" + pascal(f.Name) } // StructField returns the struct member of the field. func (f Field) StructField() string { @@ -375,7 +375,6 @@ func (f Field) Column() *schema.Column { c.Increment = true } if f.def != nil { - c.Default = f.def.Value if f.def.Size != nil { c.Size = *f.def.Size } @@ -383,6 +382,11 @@ func (f Field) Column() *schema.Column { c.Charset = *f.def.Charset } } + if f.HasDefault && !f.IsTime() { + // since this column is used only for codegen, the actual default + // value is imported by the migrate package and used directly. + c.Default = true + } return c } diff --git a/entc/gen/type_test.go b/entc/gen/type_test.go index b2d5253f5..614e68f34 100644 --- a/entc/gen/type_test.go +++ b/entc/gen/type_test.go @@ -159,7 +159,7 @@ func TestField_Constant(t *testing.T) { } } -func TestField_DefaultConstant(t *testing.T) { +func TestField_DefaultName(t *testing.T) { tests := []struct { name string constant string @@ -170,7 +170,7 @@ func TestField_DefaultConstant(t *testing.T) { } for _, tt := range tests { typ := &Field{Name: tt.name} - require.Equal(t, tt.constant, typ.DefaultConstant()) + require.Equal(t, tt.constant, typ.DefaultName()) } } diff --git a/entc/integration/ent/card.go b/entc/integration/ent/card.go index f22bba426..b2a780071 100644 --- a/entc/integration/ent/card.go +++ b/entc/integration/ent/card.go @@ -6,6 +6,7 @@ import ( "bytes" "fmt" "strconv" + "time" "fbc/ent/dialect/gremlin" "fbc/ent/dialect/sql" @@ -18,23 +19,28 @@ type Card struct { ID string `json:"id,omitempty"` // Number holds the value of the "number" field. Number string `json:"number,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` } // FromRows scans the sql response data into Card. func (c *Card) FromRows(rows *sql.Rows) error { var vc struct { - ID int - Number string + ID int + Number string + CreatedAt time.Time } // the order here should be the same as in the `card.Columns`. if err := rows.Scan( &vc.ID, &vc.Number, + &vc.CreatedAt, ); err != nil { return err } c.ID = strconv.Itoa(vc.ID) c.Number = vc.Number + c.CreatedAt = vc.CreatedAt return nil } @@ -45,14 +51,16 @@ func (c *Card) FromResponse(res *gremlin.Response) error { return err } var vc struct { - ID string `json:"id,omitempty"` - Number string `json:"number,omitempty"` + ID string `json:"id,omitempty"` + Number string `json:"number,omitempty"` + CreatedAt int64 `json:"created_at,omitempty"` } if err := vmap.Decode(&vc); err != nil { return err } c.ID = vc.ID c.Number = vc.Number + c.CreatedAt = time.Unix(vc.CreatedAt, 0) return nil } @@ -85,6 +93,7 @@ func (c *Card) String() string { buf.WriteString("Card(") buf.WriteString(fmt.Sprintf("id=%v", c.ID)) buf.WriteString(fmt.Sprintf(", number=%v", c.Number)) + buf.WriteString(fmt.Sprintf(", created_at=%v", c.CreatedAt)) buf.WriteString(")") return buf.String() } @@ -117,16 +126,18 @@ func (c *Cards) FromResponse(res *gremlin.Response) error { return err } var vc []struct { - ID string `json:"id,omitempty"` - Number string `json:"number,omitempty"` + ID string `json:"id,omitempty"` + Number string `json:"number,omitempty"` + CreatedAt int64 `json:"created_at,omitempty"` } if err := vmap.Decode(&vc); err != nil { return err } for _, v := range vc { *c = append(*c, &Card{ - ID: v.ID, - Number: v.Number, + ID: v.ID, + Number: v.Number, + CreatedAt: time.Unix(v.CreatedAt, 0), }) } return nil diff --git a/entc/integration/ent/card/card.go b/entc/integration/ent/card/card.go index e50bd1735..4b1fec3de 100644 --- a/entc/integration/ent/card/card.go +++ b/entc/integration/ent/card/card.go @@ -3,6 +3,8 @@ package card import ( + "time" + "fbc/ent/entc/integration/ent/schema" ) @@ -13,6 +15,8 @@ const ( FieldID = "id" // FieldNumber holds the string denoting the number vertex property in the database. FieldNumber = "number" + // FieldCreatedAt holds the string denoting the created_at vertex property in the database. + FieldCreatedAt = "created_at" // Table holds the table name of the card in the database. Table = "cards" @@ -32,10 +36,13 @@ const ( var Columns = []string{ FieldID, FieldNumber, + FieldCreatedAt, } var ( fields = schema.Card{}.Fields() // NumberValidator is a validator for the "number" field. It is called by the builders before save. NumberValidator = fields[0].Validators()[0].(func(string) error) + // DefaultCreatedAt holds the default value for the created_at field. + DefaultCreatedAt = fields[1].Value().(func() time.Time) ) diff --git a/entc/integration/ent/card/where.go b/entc/integration/ent/card/where.go index 08610a3b5..e80139d4a 100644 --- a/entc/integration/ent/card/where.go +++ b/entc/integration/ent/card/where.go @@ -4,6 +4,7 @@ package card import ( "strconv" + "time" "fbc/ent/entc/integration/ent/predicate" @@ -168,6 +169,18 @@ func Number(v string) predicate.Card { ) } +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Card { + return predicate.CardPerDialect( + func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreatedAt), v)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.EQ(v)) + }, + ) +} + // NumberEQ applies the EQ predicate on the "number" field. func NumberEQ(v string) predicate.Card { return predicate.CardPerDialect( @@ -320,6 +333,122 @@ func NumberHasSuffix(v string) predicate.Card { ) } +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Card { + return predicate.CardPerDialect( + func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreatedAt), v)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.EQ(v)) + }, + ) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Card { + return predicate.CardPerDialect( + func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.NEQ(v)) + }, + ) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Card { + return predicate.CardPerDialect( + func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldCreatedAt), v)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.GT(v)) + }, + ) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Card { + return predicate.CardPerDialect( + func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldCreatedAt), v)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.GTE(v)) + }, + ) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Card { + return predicate.CardPerDialect( + func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldCreatedAt), v)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.LT(v)) + }, + ) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Card { + return predicate.CardPerDialect( + func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldCreatedAt), v)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.LTE(v)) + }, + ) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Card { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.CardPerDialect( + func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(vs) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldCreatedAt), v...)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.Within(v...)) + }, + ) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Card { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.CardPerDialect( + func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(vs) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) + }, + func(t *dsl.Traversal) { + t.Has(Label, FieldCreatedAt, p.Without(v...)) + }, + ) +} + // HasOwner applies the HasEdge predicate on the "owner" edge. func HasOwner() predicate.Card { return predicate.CardPerDialect( diff --git a/entc/integration/ent/card_create.go b/entc/integration/ent/card_create.go index 65bf9b36f..07d21e4fd 100644 --- a/entc/integration/ent/card_create.go +++ b/entc/integration/ent/card_create.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "strconv" + "time" "fbc/ent/entc/integration/ent/card" "fbc/ent/entc/integration/ent/user" @@ -23,8 +24,9 @@ import ( // CardCreate is the builder for creating a Card entity. type CardCreate struct { config - number *string - owner map[string]struct{} + number *string + created_at *time.Time + owner map[string]struct{} } // SetNumber sets the number field. @@ -33,6 +35,20 @@ func (cc *CardCreate) SetNumber(s string) *CardCreate { return cc } +// SetCreatedAt sets the created_at field. +func (cc *CardCreate) SetCreatedAt(t time.Time) *CardCreate { + cc.created_at = &t + return cc +} + +// SetNillableCreatedAt sets the created_at field if the given value is not nil. +func (cc *CardCreate) SetNillableCreatedAt(t *time.Time) *CardCreate { + if t != nil { + cc.SetCreatedAt(*t) + } + return cc +} + // SetOwnerID sets the owner edge to User by id. func (cc *CardCreate) SetOwnerID(id string) *CardCreate { if cc.owner == nil { @@ -63,6 +79,10 @@ func (cc *CardCreate) Save(ctx context.Context) (*Card, error) { if err := card.NumberValidator(*cc.number); err != nil { return nil, fmt.Errorf("ent: validator failed for field \"number\": %v", err) } + if cc.created_at == nil { + v := card.DefaultCreatedAt() + cc.created_at = &v + } if len(cc.owner) > 1 { return nil, errors.New("ent: multiple assignments on a unique edge \"owner\"") } @@ -99,6 +119,10 @@ func (cc *CardCreate) sqlSave(ctx context.Context) (*Card, error) { builder.Set(card.FieldNumber, *cc.number) c.Number = *cc.number } + if cc.created_at != nil { + builder.Set(card.FieldCreatedAt, *cc.created_at) + c.CreatedAt = *cc.created_at + } query, args := builder.Query() if err := tx.Exec(ctx, query, args, &res); err != nil { return nil, rollback(tx, err) @@ -160,6 +184,9 @@ func (cc *CardCreate) gremlin() *dsl.Traversal { if cc.number != nil { v.Property(dsl.Single, card.FieldNumber, *cc.number) } + if cc.created_at != nil { + v.Property(dsl.Single, card.FieldCreatedAt, *cc.created_at) + } for id := range cc.owner { v.AddE(user.CardLabel).From(g.V(id)).InV() constraints = append(constraints, &constraint{ diff --git a/entc/integration/ent/card_update.go b/entc/integration/ent/card_update.go index c64825e32..2ed564d1c 100644 --- a/entc/integration/ent/card_update.go +++ b/entc/integration/ent/card_update.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "strconv" + "time" "fbc/ent/entc/integration/ent/card" "fbc/ent/entc/integration/ent/predicate" @@ -25,6 +26,7 @@ import ( type CardUpdate struct { config number *string + created_at *time.Time owner map[string]struct{} clearedOwner bool predicates []predicate.Card @@ -42,6 +44,20 @@ func (cu *CardUpdate) SetNumber(s string) *CardUpdate { return cu } +// SetCreatedAt sets the created_at field. +func (cu *CardUpdate) SetCreatedAt(t time.Time) *CardUpdate { + cu.created_at = &t + return cu +} + +// SetNillableCreatedAt sets the created_at field if the given value is not nil. +func (cu *CardUpdate) SetNillableCreatedAt(t *time.Time) *CardUpdate { + if t != nil { + cu.SetCreatedAt(*t) + } + return cu +} + // SetOwnerID sets the owner edge to User by id. func (cu *CardUpdate) SetOwnerID(id string) *CardUpdate { if cu.owner == nil { @@ -148,6 +164,10 @@ func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) { update = true builder.Set(card.FieldNumber, *cu.number) } + if cu.created_at != nil { + update = true + builder.Set(card.FieldCreatedAt, *cu.created_at) + } if update { query, args := builder.Query() if err := tx.Exec(ctx, query, args, &res); err != nil { @@ -220,6 +240,9 @@ func (cu *CardUpdate) gremlin() *dsl.Traversal { if cu.number != nil { v.Property(dsl.Single, card.FieldNumber, *cu.number) } + if cu.created_at != nil { + v.Property(dsl.Single, card.FieldCreatedAt, *cu.created_at) + } if cu.clearedOwner { tr := rv.Clone().InE(user.CardLabel).Drop().Iterate() trs = append(trs, tr) @@ -251,6 +274,7 @@ type CardUpdateOne struct { config id string number *string + created_at *time.Time owner map[string]struct{} clearedOwner bool } @@ -261,6 +285,20 @@ func (cuo *CardUpdateOne) SetNumber(s string) *CardUpdateOne { return cuo } +// SetCreatedAt sets the created_at field. +func (cuo *CardUpdateOne) SetCreatedAt(t time.Time) *CardUpdateOne { + cuo.created_at = &t + return cuo +} + +// SetNillableCreatedAt sets the created_at field if the given value is not nil. +func (cuo *CardUpdateOne) SetNillableCreatedAt(t *time.Time) *CardUpdateOne { + if t != nil { + cuo.SetCreatedAt(*t) + } + return cuo +} + // SetOwnerID sets the owner edge to User by id. func (cuo *CardUpdateOne) SetOwnerID(id string) *CardUpdateOne { if cuo.owner == nil { @@ -371,6 +409,11 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (c *Card, err error) { builder.Set(card.FieldNumber, *cuo.number) c.Number = *cuo.number } + if cuo.created_at != nil { + update = true + builder.Set(card.FieldCreatedAt, *cuo.created_at) + c.CreatedAt = *cuo.created_at + } if update { query, args := builder.Query() if err := tx.Exec(ctx, query, args, &res); err != nil { @@ -444,6 +487,9 @@ func (cuo *CardUpdateOne) gremlin(id string) *dsl.Traversal { if cuo.number != nil { v.Property(dsl.Single, card.FieldNumber, *cuo.number) } + if cuo.created_at != nil { + v.Property(dsl.Single, card.FieldCreatedAt, *cuo.created_at) + } if cuo.clearedOwner { tr := rv.Clone().InE(user.CardLabel).Drop().Iterate() trs = append(trs, tr) diff --git a/entc/integration/ent/example_test.go b/entc/integration/ent/example_test.go index 2334f8a3a..0e91e2b4c 100644 --- a/entc/integration/ent/example_test.go +++ b/entc/integration/ent/example_test.go @@ -33,6 +33,7 @@ func ExampleCard() { c := client.Card. Create(). SetNumber("string"). + SetCreatedAt(time.Now()). SaveX(ctx) log.Println("card created:", c) @@ -299,6 +300,7 @@ func ExampleUser() { c0 := client.Card. Create(). SetNumber("string"). + SetCreatedAt(time.Now()). SaveX(ctx) log.Println("card created:", c0) pe1 := client.Pet. diff --git a/entc/integration/ent/migrate/schema.go b/entc/integration/ent/migrate/schema.go index 3904c225e..88fbe33be 100644 --- a/entc/integration/ent/migrate/schema.go +++ b/entc/integration/ent/migrate/schema.go @@ -16,6 +16,7 @@ var ( CardsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "number", Type: field.TypeString}, + {Name: "created_at", Type: field.TypeTime}, {Name: "owner_id", Type: field.TypeInt, Unique: true, Nullable: true}, } // CardsTable holds the schema information for the "cards" table. @@ -26,7 +27,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "cards_users_card", - Columns: []*schema.Column{CardsColumns[2]}, + Columns: []*schema.Column{CardsColumns[3]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, diff --git a/entc/integration/ent/schema/card.go b/entc/integration/ent/schema/card.go index db1a22856..3392b1cd3 100644 --- a/entc/integration/ent/schema/card.go +++ b/entc/integration/ent/schema/card.go @@ -1,6 +1,8 @@ package schema import ( + "time" + "fbc/ent" "fbc/ent/schema/edge" "fbc/ent/schema/field" @@ -16,6 +18,8 @@ func (Card) Fields() []ent.Field { return []ent.Field{ field.String("number"). MinLen(1), + field.Time("created_at"). + Default(time.Now), } } diff --git a/entc/integration/integration_test.go b/entc/integration/integration_test.go index fe161576c..5bceadb0e 100644 --- a/entc/integration/integration_test.go +++ b/entc/integration/integration_test.go @@ -116,6 +116,7 @@ var tests = []func(*testing.T, *ent.Client){ M2MSelfRef, M2MSameType, M2MTwoTypes, + DefaultValue, } func Sanity(t *testing.T, client *ent.Client) { @@ -1836,6 +1837,12 @@ func Tx(t *testing.T, client *ent.Client) { require.NoError(tx.Rollback()) } +func DefaultValue(t *testing.T, client *ent.Client) { + ctx := context.Background() + c1 := client.Card.Create().SetNumber("102030").SaveX(ctx) + require.False(t, c1.CreatedAt.IsZero()) +} + func drop(t *testing.T, client *ent.Client) { t.Log("drop data from database") ctx := context.Background() diff --git a/entc/load/bindata.go b/entc/load/bindata.go index 75426848e..c24c60a4d 100644 --- a/entc/load/bindata.go +++ b/entc/load/bindata.go @@ -82,12 +82,12 @@ func templateMainTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/main.tmpl", size: 647, mode: os.FileMode(420), modTime: time.Unix(1566121519, 0)} + info := bindataFileInfo{name: "template/main.tmpl", size: 647, mode: os.FileMode(420), modTime: time.Unix(1566131522, 0)} a := &asset{bytes: bytes, info: info} return a, nil } -var _schemaGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x57\xdf\x6f\xdb\xb6\x13\x7f\xb6\xfe\x8a\xfb\x1a\x68\x20\x15\x86\xf3\xae\xc2\x0f\x5f\x6c\x19\x96\x0d\x4b\x87\x76\xdb\x4b\x51\xb4\x8c\x74\x72\xd8\xca\x94\x4b\xd2\x4e\xdb\xc0\xff\xfb\x70\x3f\x68\x49\x96\x9b\x01\x2d\x52\xa0\x88\x78\xbf\x78\xf7\xb9\x0f\x8f\xf4\xd6\x54\x1f\xcd\x1a\xa1\xed\x4c\x9d\x65\x76\xb3\xed\x7c\x84\x3c\x9b\xcd\xd1\x55\x5d\x6d\xdd\xfa\xf2\x43\xe8\xdc\x3c\x9b\xcd\x9b\xdb\xea\x12\x5d\x1c\x7c\x5e\x86\xea\x0e\x37\xe6\xb2\xb1\xd8\xd6\x2c\xdf\xb0\xda\x63\xd3\x62\x15\xe7\x59\x91\x65\x97\x97\xf0\x9a\xad\xc0\xe3\xd6\x63\x40\x17\x03\x18\x07\xe8\xe2\x52\x15\xf1\xce\x44\xb8\x37\x81\x73\xc0\x1a\x1a\xdf\x6d\xc0\x40\xd5\x6d\xb6\xad\xc5\x1a\x76\x01\x3d\x68\x9e\xcb\x2c\x7e\xd9\x62\x0a\x19\xa2\xdf\x55\x11\x1e\xb2\xd9\x8d\xd9\x20\x00\x90\xc4\xba\x35\x00\xbc\xa7\xb4\xcb\xb9\x33\x1b\x5c\x74\x1b\x1b\x71\xb3\x8d\x5f\xe6\xef\xb3\xd9\x55\xbd\xc6\x00\x00\x6f\xde\x3e\xa7\xcf\xa3\x25\x92\x7c\x6c\xfa\x0b\xd5\x15\xd8\x94\x3f\x93\x29\xd7\x7b\x62\x7b\xed\x6a\xfc\x8c\x81\x6c\xf9\x33\xd9\x5a\x91\x8f\x8c\x0f\x0c\x8b\x84\x9c\xa2\x22\xf2\xef\x00\x45\x1c\xa7\x98\x0c\x61\x79\x0c\x99\xbf\x28\x88\xfc\xe3\x0a\x97\x22\x50\x7b\xda\xe2\xc4\xde\x68\xc4\xb3\xf1\xa3\x59\x8f\xcd\x5f\xdb\xaf\x29\xfc\x73\xeb\x62\x72\x55\xf3\x60\xbf\x9e\x84\xff\xe9\xce\xf8\x80\x6c\xf7\x7c\x10\x5f\xed\x2b\xd1\x8e\x5d\xfe\x76\xf6\xd3\x4e\x36\xb9\xed\xba\xf6\x64\x8b\x1d\x6b\xc7\x1e\x37\xb6\x6d\xcd\x6d\x8b\xe7\x3d\x9c\x6a\xc7\x3e\x2f\xb7\xd1\x76\xce\xb4\xe7\x7d\x3a\xd5\x8e\x7d\x7e\xc6\xc6\xec\xda\xf8\x8d\xcc\x6a\xd1\x8e\x5d\xfe\x31\xad\xd6\x02\xd6\x45\xf4\x8d\xa9\xf0\xe1\x90\x5c\xf6\xa4\x9d\x38\xd8\xda\xc4\xce\x07\x18\xe0\x3b\x70\x50\xed\x19\x2e\xf2\x49\x98\x52\x91\xc5\xdf\xc1\x44\xf6\x3b\x43\x44\x6d\xe3\x7f\x33\x70\x6c\xf8\x08\xf5\x4e\x0c\x4f\x39\xf7\x0a\x1b\xd9\x7c\x6c\xe7\xb1\x79\x37\xdd\xfd\x15\x36\x4a\xcf\xd1\x60\xf0\xd8\x7c\x83\x65\xda\xc9\x47\xe8\x75\xed\xf6\xe8\x03\x9e\x9a\x5a\x11\x9f\x6e\xff\x69\x67\x3d\xd6\x27\xb6\x5e\xc5\x67\xba\x26\x83\x66\xda\x36\x91\x7f\x47\xdf\xc4\xb1\x6f\x9c\x56\x7a\x64\xec\x23\x95\x0a\x64\x93\xf9\x4b\x53\xf5\xec\x50\x7d\xf3\x76\xdc\x92\x33\x33\x55\x8a\xbc\xc1\x7b\x8e\x5d\x79\x34\x11\xb9\x46\x2d\x88\x62\x4b\x55\x72\x0f\xf5\xc7\x64\x99\x35\x3b\x57\x25\xd7\x1c\x8f\x64\x2e\xb4\xb7\x0f\xd9\xcc\x21\x94\x2b\xb8\xa0\xe5\x43\x36\x63\x8e\x96\x5c\x24\x2e\xe9\x3b\x2f\x16\xd9\x8c\x09\x99\xa4\xf4\xad\x52\xb3\x16\x21\x49\xcd\x5a\x84\x4a\xb5\x92\x84\xfa\x2d\x0a\x01\xb1\x64\xeb\xeb\x20\x2b\xd1\x28\x3b\x4a\xd1\xe8\x2a\x45\x93\xae\x97\xac\x4a\x2b\xd6\x1d\xb2\x99\x6d\x80\xb3\xc7\xe5\xff\x43\xe8\xaa\xbc\x78\x01\x08\xff\x5b\x81\xb3\x2d\x95\x36\x73\x9c\x02\xac\x7a\x04\x0a\xf6\xf3\x18\x77\xde\x81\x43\xc5\xf6\x0f\xe3\xc3\x9d\x69\xf5\x36\xe5\x1b\x9f\xce\x3b\x0e\x6f\xe7\x23\xa8\xf4\xd5\x81\x81\xdf\x5e\xbf\xbc\x21\x67\xe6\x57\x65\x1c\xdc\x22\xd4\x48\xae\xb5\x98\x50\x00\x75\xee\x6e\x3f\x60\x15\xf5\x8f\x76\x65\xb4\x69\x1e\xd2\xde\x44\x5b\xdd\xa9\x80\xfc\x16\xde\xbc\xbd\xfd\x12\x71\x01\xe8\x3d\xfd\xef\x7c\x41\xa5\x05\x6e\x9a\xf8\x3e\x08\xde\xd6\xd5\xd6\x63\x15\x73\x7d\x76\x70\xa3\x5e\x36\x1a\xb9\x28\xb4\x9d\x87\x6c\xa6\x1c\xe3\x90\xe5\x0a\x82\x69\x50\xd8\x98\x6c\x05\x59\xef\x87\x58\x26\xcc\x6c\xbb\x80\x66\x13\x97\x57\x94\x4b\x93\xcf\x35\xf1\x67\x9f\x4a\x78\xb6\x9f\x2f\x20\xf0\x3e\x1c\x5c\xc0\x6e\x3a\x0f\xef\x16\xd0\xd0\x56\xde\x38\xe2\xaa\x50\x9f\xa2\x06\x16\x5f\xf0\xf6\xb4\x1e\xf0\x0f\xa0\x19\x30\x70\x40\x41\x52\xf4\x24\x1c\xb0\x90\x15\x89\x87\x72\x6f\x94\x49\xce\x2b\xd5\xf4\x4c\x24\xcd\x98\x8b\xe9\x86\x2a\x45\xf9\xab\x09\x2a\x50\x75\xba\x28\x4b\xf5\x4d\x6b\x55\xa7\x3b\x31\xa9\xd3\xba\xcf\x49\x2f\x9f\x12\x5a\x74\x39\xe7\xa5\x92\xbc\x60\x9b\x43\x36\x23\xf4\xc3\x02\xba\x8f\x84\x4d\xb3\xcc\xe5\x15\x42\xef\x06\x5f\xbc\x20\x31\x23\x45\x2f\x05\x6e\x1f\x6b\xf2\x82\x65\x0d\x2f\x60\x05\x17\xa4\xee\xc3\x55\x93\x70\xfa\xac\x18\x85\xd4\xc7\x04\xd9\x55\xc9\xe0\x18\x38\xbd\x43\x56\x70\xa1\x76\x1a\x3e\x2c\x75\x96\xad\xc0\x6c\xb7\xe8\xea\x3c\x49\x16\x10\x1a\x21\x81\xbc\x2a\x87\x8c\xe3\xf7\xe7\x53\x12\x0e\x7b\xc2\xf1\xee\xc2\xb7\xa5\xbc\x7b\x07\xa9\x5e\x49\x6a\xfd\x88\x90\x28\xe9\xc1\x3a\xcc\x59\x1f\xb7\x4f\x99\xb5\xad\x3f\xf7\x79\x6b\x0e\x9a\x79\x7a\x5a\x0f\x72\xbf\x4e\x49\x5e\xf0\x17\x37\x91\xaa\x20\xfa\xd9\xfa\x33\xd7\xa6\xd4\x93\x8e\x94\x2c\xd6\xd3\x3e\x3e\x0d\xa4\x18\x9f\x85\xc3\x68\x5a\xd2\xfd\xb4\xd4\xa1\x95\x87\x42\x47\x67\x3f\x3c\xe0\xde\x9b\x6d\xe0\xa9\x27\xc5\x26\x5a\x6c\x30\xde\x75\x35\xdc\xdb\x78\x07\x1e\xab\x6e\x8f\x1e\x62\x07\xe8\xc2\xce\x23\xb8\x0e\xb6\xc6\xd9\x8a\x1e\x6b\xb0\x91\xf0\xd6\xad\x75\x48\x4e\x66\xd3\x64\x42\x36\xe9\x1e\x3d\xfe\x66\x38\x9d\x95\x35\x36\xe8\x81\xc2\xe5\xbc\xa6\xae\xed\x19\x64\x49\x86\xae\x8d\xfd\xb0\x87\x33\xf2\x5f\x9d\x69\x5f\xaa\x48\x12\xd6\x4e\xee\xf9\x80\x34\xe9\x08\x38\xdb\xca\xb9\x38\xd0\xc9\x51\xec\x46\xee\x79\xb1\x60\xab\x1e\x40\xe1\xe4\x04\x3f\x11\xff\x28\x7c\xc3\x83\x36\x41\x4f\x4e\x86\x80\x47\x86\x4f\x88\x9d\x54\x73\x06\x3a\xd4\x13\xf9\x18\x72\x52\xc4\x04\xb8\x74\x24\x26\xd0\x25\xc5\x8f\x82\x37\x3e\xf1\x13\xf8\xec\xf1\xd7\xee\xf1\xbd\xf9\x84\x08\xa6\xa2\xce\x60\x68\x8f\xb3\xe1\x31\x14\x53\x35\x3d\x8e\x5c\xe8\xf1\xe5\x10\x61\xf8\x76\x28\x46\x2b\xca\x8d\x66\x54\x5c\xfe\x6e\x5d\x9d\x17\xb0\x5a\x1d\xf5\x7f\x46\xcf\xa9\xd3\xe5\x10\x97\x57\x2d\x6e\xf2\xd1\xe8\x88\xd9\x21\xfb\x37\x00\x00\xff\xff\xdb\x1a\x88\xcc\x61\x11\x00\x00") +var _schemaGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x57\xdf\x6f\xdb\xb6\x13\x7f\xb6\xfe\x8a\xfb\x1a\x68\x20\x15\x86\xf2\xee\xc2\x0f\x5f\x6c\x19\x96\x0d\x4b\x87\x76\xdb\x4b\x51\xb4\x8c\x74\x72\xd8\xca\x94\x4b\xd2\x4e\xdb\xc0\xff\xfb\x70\x3f\x68\x49\x96\x9b\x01\x2d\x52\xa0\xb0\x78\xbf\x78\xf7\xb9\x0f\x8f\xcc\xd6\x54\x1f\xcd\x1a\xa1\xed\x4c\x9d\x65\x76\xb3\xed\x7c\x84\x3c\x9b\xcd\xd1\x55\x5d\x6d\xdd\xfa\xf2\x43\xe8\xdc\x3c\x9b\xcd\x9b\x4d\xa4\x1f\x8f\x4d\x8b\x55\x9c\x67\x24\xba\xad\x2e\xd1\xb1\x58\x3f\x2f\x43\x75\x87\x1b\x73\xd9\x58\x6c\xeb\x79\x56\x64\xd9\xe5\x25\xbc\x66\x19\x78\xdc\x7a\x0c\xe8\x62\x00\xe3\x00\x5d\x2c\x55\x11\xef\x4c\x84\x7b\x13\x38\x09\xac\xa1\xf1\xdd\x06\x0c\x54\xdd\x66\xdb\x5a\xac\x61\x17\xd0\x83\x26\x5a\x66\xf1\xcb\x16\x53\xc8\x10\xfd\xae\x8a\xf0\x90\xcd\x6e\xcc\x06\x01\x80\x24\xd6\xad\x01\xe0\x3d\xe5\xbd\x9c\x3b\xb3\xc1\x45\xb7\xb1\x11\x37\xdb\xf8\x65\xfe\x3e\x9b\x5d\xd5\x6b\x0c\x00\xf0\xe6\xed\x73\xfa\x3c\x5a\x22\xc9\xc7\xa6\xbf\x50\x15\x81\x4d\xf9\x33\x99\x72\x75\x27\xb6\xd7\xae\xc6\xcf\x18\xc8\x96\x3f\x93\xad\x15\xf9\xc8\xf8\xc0\xb0\x48\xc8\x29\x2a\x22\xff\x0e\x50\xc4\x71\x8a\xc9\x10\x96\x47\x80\xf9\x8b\x62\xc8\x3f\x2e\xb0\x64\x81\x9a\xd3\x06\x27\xe6\x66\x0d\xdf\x8c\x1e\xcd\x7a\x6c\xfd\xda\x7e\x4d\xc1\x9f\x5b\x17\xf5\x53\xad\x83\xfd\x7a\x12\xfc\xa7\x3b\xe3\x03\xb2\xd9\xf3\x3e\xba\x9a\x57\xa2\x1c\x7b\xfc\xed\xec\xa7\x9d\x6c\x71\xdb\x75\xed\x78\x83\x1d\x2b\xc7\x0e\x37\xb6\x6d\xcd\x6d\x8b\x67\x1d\x9c\x2a\xc7\x2e\x2f\xb7\xd1\x76\xce\xb4\x67\x5d\x3a\x55\x8e\x5d\x7e\xc6\xc6\xec\xda\x78\x3e\xad\x5a\x94\x63\x8f\x7f\x4c\x6b\x6b\x13\x3b\x1f\xa0\x07\x2a\x79\xec\x8f\xca\x33\x84\x62\x3a\x4f\xf9\xc4\xe2\xef\xa0\x13\xfb\x9d\x61\x93\xf6\xe3\xbf\x79\x34\x36\x7c\x84\x41\x27\x86\xa7\xdc\x79\x85\x8d\x6c\x3e\xb6\xf3\xd8\xbc\x9b\xee\xfe\x0a\x1b\xa5\xd9\xe8\x74\x7b\x6c\xbe\xc1\x17\x6d\xcb\x23\x4c\xb9\x76\x7b\xf4\x01\x4f\x4d\xad\x88\x4f\xb7\xff\xb4\xb3\x1e\xeb\x13\x5b\xaf\xe2\x33\x5d\x93\x69\x31\x6d\x9b\xc8\xbf\xa3\x6f\xe2\xd8\x37\x4e\x2b\x3d\xd2\xef\x91\x4a\x05\xb2\xc9\x10\xa5\xd1\x78\x76\x32\xbe\x79\x3b\x6e\xc9\x99\xc1\x28\x45\xde\xe0\x3d\xc7\xae\x3c\x9a\x88\x5c\xa3\x16\x44\xb1\xa5\x2a\xb9\x3a\x88\xf4\xe8\x1b\x53\x61\x99\x35\x3b\x57\x25\xd7\x1c\x8f\x64\x2e\xb4\xb7\x0f\xd9\xcc\x21\x2c\x57\x70\x41\xcb\x87\x6c\xc6\x1c\x5d\x72\x91\x58\xd2\x77\x5e\x2c\xb2\x19\x13\x32\x49\xe9\x5b\xa5\x66\x2d\x42\x92\x9a\xb5\x08\x95\x6a\x4b\x12\xea\xb7\x28\x04\xc4\x25\x5b\x5f\x07\x59\x89\x46\xd9\xb1\x14\x8d\xae\x52\x34\xe9\xfa\x92\x55\x69\xc5\xba\x43\x36\xb3\x0d\x70\xf6\x58\xfe\x3f\x84\xae\xca\x8b\x17\x80\xf0\xbf\x15\x38\xdb\x52\x69\x33\xc7\x29\xc0\xaa\x47\xa0\x60\x3f\x8f\x71\xe7\x1d\x38\x54\x6c\xff\x30\x3e\xdc\x99\x56\xaf\x44\xbe\xb7\xe9\xbc\xe3\xf0\x8a\x3d\x82\x4a\x5f\x1d\x18\xf8\xed\xf5\xcb\x1b\x72\x66\x7e\x55\xc6\xc1\x2d\x42\x8d\xe4\x5a\x8b\x09\x05\x50\xe7\xee\xf6\x03\x56\x51\x7f\xb4\x2b\xa3\x4d\xf3\x90\xf6\x26\xda\xea\x4e\x05\xe4\xb7\xf0\xe6\xed\xed\x97\x88\x0b\x40\xef\xe9\x7f\xe7\x0b\x2a\x2d\x70\xd3\xc4\xf7\x41\xf0\xb6\xae\xb6\x1e\xab\x98\xeb\xfb\x82\x1b\xf5\xb2\xd1\xc8\x45\xa1\xed\x3c\x64\x33\xe5\x18\x87\x5c\xae\x20\x98\x06\x85\x8d\xc9\x56\x90\xf5\x7e\x88\x65\xc2\xcc\xb6\x0b\x68\x36\xb1\xbc\xa2\x5c\x9a\x7c\xae\x89\x3f\xfb\xb4\x84\x67\xfb\xf9\x02\x02\xef\xc3\xc1\x05\xec\xa6\xf3\xf0\x6e\x01\x0d\x6d\xe5\x8d\x23\xae\x0a\xf5\x29\x6a\x60\xf1\x05\x6f\x4f\xeb\x01\xff\x00\x9a\x01\x03\x07\x14\x24\x45\x4f\xc2\x01\x0b\x59\x91\x78\x38\xe0\x1b\xc9\xc7\x8c\x4b\x97\xca\x52\x94\xbf\x9a\xa0\x02\x55\xa7\x9b\x6d\xa9\xbe\x69\xad\xea\x74\x8b\x25\x75\x5a\xab\xba\xbf\x7f\x96\xd0\xa2\xcb\x9b\xb2\x97\xe4\x05\xdb\x1c\xb2\x19\x61\x1c\x16\xd0\x7d\x24\x04\x9a\x32\x97\x17\x03\xdd\xf2\xbe\x78\x41\x62\xc6\x83\x2e\x76\x6e\x12\x6b\xf2\x82\x65\x0d\x2f\x60\x05\x17\xa4\xee\xc3\x55\x93\x70\xfa\x0a\x18\x85\xd4\xcb\x9f\xec\xaa\x64\x70\x0c\x9c\x9e\x0d\x2b\xb8\x50\x3b\x0d\x1f\x4a\x9d\x58\x2b\x30\xdb\x2d\xba\x3a\x4f\x92\x05\x84\x46\x5a\x2d\x0f\xc0\x21\xaf\xf8\xa9\xf8\x94\xb4\xc2\x9e\x56\xbc\xbb\xb0\xaa\x94\x27\xea\x20\xd5\x2b\x49\xad\x1f\x04\x12\x25\xbd\x2d\x87\x39\xeb\x3b\xf4\x29\xb3\xb6\xf5\xe7\x3e\x6f\xcd\x41\x33\x4f\xaf\xe0\x41\xee\xd7\x29\xc9\x0b\xfe\xe2\x26\x52\x15\x44\x3f\x5b\x7f\xe6\xda\x94\x7a\xd2\x91\x25\x8b\xf5\x4c\x8f\x4f\x03\x29\xc6\x67\xe1\x30\x9a\x89\x74\x0b\x95\x3a\x9a\xf2\x50\xe8\x80\xec\x47\x04\xdc\x7b\xb3\x0d\x3c\xdb\xa4\xd8\x44\x8b\x0d\xc6\xbb\xae\x86\x7b\x1b\xef\xc0\x63\xd5\xed\xd1\x43\xec\x00\x5d\xd8\x79\x04\xd7\xc1\xd6\x38\x5b\xd1\x8b\x0c\x36\x12\xde\xba\xb5\x8e\xc2\xc9\x04\x9a\xcc\xc1\x26\xdd\x96\xc7\xe7\xfd\xe9\x44\xac\xb1\x41\x0f\x14\x2e\xe7\x35\x75\x6d\xcf\x20\x4b\x32\x74\x39\xec\x87\x3d\x9c\x91\xff\xea\x4c\xfb\x52\x45\x92\xb0\x76\x72\xcf\x07\xa4\x49\x47\xc0\xd9\x56\xce\xc5\x81\x4e\x8e\x62\x37\x72\xcf\x8b\x05\x5b\xf5\x00\x0a\x27\x27\xf8\x89\xf8\x47\xe1\x1b\x1e\xb4\x09\x7a\x72\x32\x04\x3c\x32\x7c\x42\xec\xa4\x9a\x33\xd0\xa1\x9e\xc8\xc7\x90\x93\x22\x26\xc0\xa5\x23\x31\x81\x2e\x29\x7e\x14\xbc\xf1\x89\x9f\xc0\x67\x8f\x7f\x98\x1e\x5f\x95\x4f\x88\x60\x2a\xea\x0c\x86\xf6\x38\x1b\x1e\x43\x31\x55\xd3\xe3\xc8\x85\x1e\xdf\x07\x11\x86\x2f\x84\x62\xb4\xa2\xdc\x68\x46\xc5\xf2\x77\xeb\xea\xbc\x80\xd5\xea\xa8\xff\x33\x7a\x4e\x9d\x2e\x87\x58\x5e\xb5\xb8\xc9\x47\xa3\x23\x66\x87\xec\xdf\x00\x00\x00\xff\xff\x8a\x04\xaf\xc2\x0d\x11\x00\x00") func schemaGoBytes() ([]byte, error) { return bindataRead( @@ -102,7 +102,7 @@ func schemaGo() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "schema.go", size: 4449, mode: os.FileMode(420), modTime: time.Unix(1566124960, 0)} + info := bindataFileInfo{name: "schema.go", size: 4365, mode: os.FileMode(420), modTime: time.Unix(1566208165, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/load/schema.go b/entc/load/schema.go index 124d40bc6..7c526b5cb 100644 --- a/entc/load/schema.go +++ b/entc/load/schema.go @@ -19,17 +19,16 @@ type Schema struct { // Field represents an ent.Field that was loaded from a complied user package. type Field struct { - Name string `json:"name,omitempty"` - Type field.Type `json:"type,omitempty"` - Tag string `json:"tag,omitempty"` - Size *int `json:"size,omitempty"` - Charset *string `json:"charset,omitempty"` - Unique bool `json:"unique,omitempty"` - Nillable bool `json:"nillable,omitempty"` - Optional bool `json:"optional,omitempty"` - Default bool `json:"default,omitempty"` - Value interface{} `json:"value,omitempty"` - Validators int `json:"validators,omitempty"` + Name string `json:"name,omitempty"` + Type field.Type `json:"type,omitempty"` + Tag string `json:"tag,omitempty"` + Size *int `json:"size,omitempty"` + Charset *string `json:"charset,omitempty"` + Unique bool `json:"unique,omitempty"` + Nillable bool `json:"nillable,omitempty"` + Optional bool `json:"optional,omitempty"` + Default bool `json:"default,omitempty"` + Validators int `json:"validators,omitempty"` } // Edge represents an ent.Edge that was loaded from a complied user package. @@ -81,7 +80,6 @@ func MarshalSchema(schema ent.Interface) (b []byte, err error) { Name: f.Name(), Type: f.Type(), Tag: f.Tag(), - Value: f.Value(), Unique: f.IsUnique(), Default: f.HasDefault(), Nillable: f.IsNillable(), diff --git a/entc/load/schema_test.go b/entc/load/schema_test.go index d2c71453e..001c54970 100644 --- a/entc/load/schema_test.go +++ b/entc/load/schema_test.go @@ -156,11 +156,7 @@ func TestMarshalDefaults(t *testing.T) { require.Equal(t, "WithDefaults", schema.Name) require.True(t, schema.Fields[0].Default) - require.Equal(t, 1.0, schema.Fields[0].Value, "marshaling converts int to float") require.True(t, schema.Fields[1].Default) - require.Equal(t, math.Pi, schema.Fields[1].Value) require.True(t, schema.Fields[2].Default) - require.Equal(t, "foo", schema.Fields[2].Value) require.True(t, schema.Fields[3].Default) - require.Equal(t, true, schema.Fields[3].Value) } diff --git a/schema/field/field.go b/schema/field/field.go index 1f5bd4b1a..9326a9aad 100644 --- a/schema/field/field.go +++ b/schema/field/field.go @@ -6,6 +6,7 @@ import ( "regexp" "strconv" "strings" + "time" ) // Type is a field type. @@ -482,6 +483,17 @@ func (b *timeBuilder) StructTag(s string) *timeBuilder { return b } +// Default sets the function that is applied to set default value +// of the field on creation. For example: +// +// field.Time("created_at"). +// Default(time.Now) +// +func (b *timeBuilder) Default(f func() time.Time) *timeBuilder { + b.value = f + return b +} + // boolBuilder is the builder for boolean fields. type boolBuilder struct { Field diff --git a/schema/field/field_test.go b/schema/field/field_test.go index 08e0becb1..4e3b5bfb6 100644 --- a/schema/field/field_test.go +++ b/schema/field/field_test.go @@ -3,6 +3,7 @@ package field_test import ( "regexp" "testing" + "time" "fbc/ent" "fbc/ent/schema/field" @@ -75,10 +76,16 @@ func TestCharset(t *testing.T) { } func TestTime(t *testing.T) { - f := field.Time("created_at") + now := time.Now() + f := field.Time("created_at"). + Default(func() time.Time { + return now + }) assert.Equal(t, "created_at", f.Name()) assert.Equal(t, field.TypeTime, f.Type()) assert.Equal(t, "time.Time", f.Type().String()) + assert.NotNil(t, f.Value()) + assert.Equal(t, now, f.Value().(func() time.Time)()) } func TestField_Tag(t *testing.T) {