ent/field: add default value for time

Reviewed By: alexsn

Differential Revision: D16890453

fbshipit-source-id: 362ae9e9666c523bdcce16503441565b6279ff08
This commit is contained in:
Ariel Mashraki
2019-08-19 04:20:19 -07:00
committed by Facebook Github Bot
parent 51a4dd4412
commit 079ba191e3
19 changed files with 294 additions and 43 deletions

View File

@@ -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
}

View File

@@ -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 }}\"")

View File

@@ -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 -}}

View File

@@ -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
}

View File

@@ -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())
}
}

View File

@@ -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

View File

@@ -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)
)

View File

@@ -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(

View File

@@ -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{

View File

@@ -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)

View File

@@ -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.

View File

@@ -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,

View File

@@ -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),
}
}

View File

@@ -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()

File diff suppressed because one or more lines are too long

View File

@@ -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(),

View File

@@ -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)
}