ent/entc: add nillable setter for nullable fields

Reviewed By: idoshveki

Differential Revision: D16599899

fbshipit-source-id: bcab65e09645409f8a822e2eebda1aac0f804c7c
This commit is contained in:
Ariel Mashraki
2019-08-01 06:52:57 -07:00
committed by Facebook Github Bot
parent 2c8b5a65b7
commit 2d962d5cba
2 changed files with 4 additions and 4 deletions

View File

@@ -184,7 +184,7 @@ func templateBuilderQueryTmpl() (*asset, error) {
return a, nil
}
var _templateBuilderSetterTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x56\x5f\x6f\x9b\x3e\x14\x7d\x26\x9f\xe2\xfe\x10\xbf\x09\xa2\xd6\xd5\x5e\x2b\xe5\x65\xca\xaa\xe5\xa5\x7b\xe8\xf6\x14\x45\x13\x8d\x2f\x99\x37\x0a\x14\x43\xa6\x8a\xf9\xbb\x4f\xd7\x36\x86\x38\xa4\x49\x35\xed\x0d\xec\x73\xff\xf8\xdc\xe3\x03\x5d\x07\x1c\x33\x51\x20\x84\x12\x9b\x06\xeb\x10\x94\x9a\x75\x1d\x44\x8f\xad\xc8\x39\xd6\x70\xbb\x80\x2a\x95\xdb\x34\x87\x88\x3d\x6c\xcb\x0a\xd9\x07\xbb\x63\x81\x35\x6e\x51\xec\x0d\xd2\x3d\xbb\x70\xa5\x66\x84\xaa\xd3\x62\x87\x10\x7d\xbb\x82\x28\x23\x60\xc4\xee\x04\xe6\x5c\xd2\x7e\x40\x59\x2a\x5a\xcd\xcb\x5f\x58\x43\x5c\xd5\xa2\x68\x32\x08\xff\x67\xef\x65\x08\x51\xc6\xbe\xbc\x54\x98\x38\x68\xd6\x16\x5b\xdd\x16\xc1\x20\x7c\xc0\x26\x84\xb8\xef\x31\x63\xf7\xe9\x93\x05\xdf\xdc\x80\xc3\x2b\x05\x12\x1b\x09\xcd\x77\x34\x8b\x1a\x47\xcb\x19\x35\xc2\x66\x81\x86\xc5\x07\x27\x52\x0a\xe6\x63\x2e\x94\x4a\xc6\x19\x63\xd3\xb8\x52\x36\x23\xb5\xa9\x31\x5e\x10\x74\xb3\x20\xf0\x12\x33\x13\xf2\xd0\xd4\xed\xb6\xd1\x5c\x10\x70\x01\xef\xfa\x9c\xb3\x20\xa8\xb1\x69\xeb\x02\xbc\xc8\x59\x60\x78\x10\x19\x94\x35\xe5\xf8\x5c\x35\xa2\x2c\xcc\xe1\x3f\xa5\x72\x89\x59\xda\xe6\x8d\xa3\xab\x10\x79\x9e\x3e\xe6\x78\x77\x44\xdb\xbd\xdd\x39\x41\x5f\xcf\xdf\x41\x82\x33\x3c\x52\x57\xb4\xb5\x13\x7b\x2c\x60\x9f\xe6\x2d\x82\x90\x50\x94\x0d\x14\x22\x67\xb3\xe0\x2d\x34\x7b\x85\x07\xba\xe7\x17\xf0\x1d\x88\x0c\x5c\xc0\x7f\x0b\x2a\x6f\xd6\xa7\x27\x61\x4b\xcc\xfb\x90\x84\xa0\x44\xc2\xc9\x29\xd8\x31\x60\xc1\xed\x4d\xb0\x4f\x9e\xdc\xd1\xc8\xfd\x23\xdf\xe1\xa0\xf6\x52\xcb\x3d\x4c\x39\xa7\xfb\x66\x86\x19\x21\xfb\x5a\x88\xe7\x16\xcd\x0a\x61\x16\xfa\x56\x5a\x88\x4d\xaf\xe3\x05\x97\x87\xe3\x74\x03\x2c\xab\x04\x62\x29\x8a\x5d\x9b\xa7\x35\xe5\xd4\xe3\xf9\x6d\xef\x70\x02\xe1\x6a\x29\x4f\xd7\xec\xf3\x4e\xa7\xed\x5f\xd0\x8a\x24\x5c\x2d\xbd\xde\xac\x62\xfa\x34\xf6\x66\x94\x44\xe8\x20\x19\x74\x92\x41\xbe\x43\x68\x4a\xbb\x4a\xe3\x74\x5b\x8f\x2f\x20\xb8\x69\x92\xc4\x33\x6e\x54\xba\x82\x6f\xbb\xb5\x43\x57\xf1\xf1\xe9\x75\x31\xcc\xa5\x79\x96\xc0\x18\x73\x65\x74\x34\x5b\x2d\x5f\x17\x9c\xd5\x9b\xaf\x2c\x3c\xba\xe3\x23\x2d\x5e\x16\x00\x4f\xe9\x4f\x8c\x9f\xd2\x6a\xed\x35\xb2\x91\x1a\xd9\x69\xb5\x2a\x63\x32\x07\xe7\xba\xd6\x42\xbd\xa8\xcc\x5a\xf0\x0d\x2c\xa0\xcf\xd8\x99\x74\xd7\x86\x13\x9b\x27\x2b\x6b\x10\xda\xe7\xb5\xbe\x89\xa7\xd3\x57\x6a\xa2\x80\x5c\x8b\xcd\x51\x91\xc0\x55\xb2\x22\x3a\xef\x7b\x69\xc1\x47\x87\x8c\x70\xb0\x40\x65\x59\x70\xde\xb1\x5a\xca\x8b\x8c\xcf\xd3\xf4\xb1\xfb\xf5\x89\x7c\x03\xbc\x5c\xcd\xff\xc4\x1b\x87\xb6\x62\xc1\x0d\xf4\xac\x52\x49\xaa\x82\x9f\x36\x45\xad\xb9\xa9\x91\x8e\x6e\xd0\x5c\xf0\xb7\x5a\xe4\xb9\xef\xfc\x88\x33\xf7\xb1\x17\x19\xe0\x33\x45\x1d\x30\x62\x12\x2d\x20\xdc\x87\xf6\x75\x5c\x22\x7b\xc5\x19\xfd\x71\x4f\xfc\x26\x9c\x75\xac\xae\xf3\x4d\x69\xec\x49\xd3\x0a\xf8\xfb\xff\x8b\x09\x23\x1c\x7b\xd4\xdc\xab\xf9\xca\x6f\xc8\x94\x43\x4c\x4f\xd0\x1f\x7a\xdf\x0f\x5b\x2d\x93\x09\x7b\x20\x3f\xb8\xb5\x6e\xb5\xde\x78\x52\xbc\x82\x1c\x0b\x97\x21\x49\x7a\x5f\xd2\x7e\x12\x8a\xe1\x9b\x44\xf3\x16\x06\x65\xf6\x17\x10\xfe\x18\x7d\x67\x46\x5e\x64\xf6\x95\x1a\x2c\x69\x60\x4c\xab\x9a\x2c\xa7\x07\x6d\xac\xa8\x69\x7b\x58\x64\xab\xe5\x19\x19\xfb\x24\x08\x2e\x19\x63\x89\x67\x5a\xe3\x3f\x80\xe1\xe9\x4f\x00\x00\x00\xff\xff\x7d\xea\xb3\xe5\x5f\x0b\x00\x00")
var _templateBuilderSetterTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x56\xcd\x6e\xdb\x3c\x10\x3c\xcb\x4f\xb1\x9f\xa0\xaf\x90\x8c\x84\x41\xaf\x01\x7c\x29\xdc\xa0\xbe\xa4\x87\xb4\x27\xc3\x28\x14\x73\xe5\xb2\x55\x28\x45\x94\x5c\x04\x2a\xdf\xbd\x58\x92\xfa\x31\x2d\xc7\x0e\x8a\xde\x24\x72\x38\xbb\xdc\x9d\x1d\xa9\x6d\x81\x63\x26\x24\x42\xa8\xb0\xae\xb1\x0a\x41\xeb\x59\xdb\x42\xf4\xd8\x88\x9c\x63\x05\xb7\x0b\x28\x53\xb5\x4d\x73\x88\xd8\xc3\xb6\x28\x91\x7d\x70\x3b\x0e\x58\xe1\x16\xc5\xde\x22\xfb\xe7\xfe\xb8\xd6\x33\x42\x55\xa9\xdc\x21\x44\xdf\xae\x20\xca\x08\x18\xb1\x3b\x81\x39\x57\xb4\x1f\x10\x4b\x49\xab\x79\xf1\x0b\x2b\x88\xcb\x4a\xc8\x3a\x83\xf0\x7f\xf6\x5e\x85\x10\x65\xec\xcb\x4b\x89\x49\x0f\xcd\x1a\xb9\x35\x69\x11\x0c\xc2\x07\xac\x43\x88\xbb\x1c\x33\x76\x9f\x3e\x39\xf0\xcd\x0d\xf4\x78\xad\x41\x61\xad\xa0\xfe\x8e\x76\xd1\xe0\x68\x39\xa3\x44\xd8\x2c\x30\xb0\xf8\xe0\x46\x5a\xc3\x7c\x5c\x0b\xad\x93\x31\x63\x6c\x13\xd7\xda\x31\x52\x9a\x06\xe3\x1d\x82\x76\x16\x04\x1e\x31\xb3\x47\x1e\xea\xaa\xd9\xd6\xa6\x16\x04\x5c\xc0\xbb\x8e\x73\x16\x04\x15\xd6\x4d\x25\xc1\x3b\x39\x0b\x6c\x1d\x44\x06\x45\x45\x1c\x9f\xcb\x5a\x14\xd2\x5d\xbe\xc9\xf3\xf4\x31\x47\x7a\xfe\x94\xaa\x25\x66\x69\x93\xd7\x96\x8e\x78\xa4\xb0\xfb\x77\x47\x35\xbc\x77\x3b\x27\x6a\xd9\x15\xf3\x80\xe0\x4c\x51\x29\x45\xda\xda\x89\x3d\x4a\xd8\xa7\x79\x83\x20\x14\xc8\xa2\x06\x29\x72\x36\x0b\xde\x52\x73\x2f\xf0\x50\xfb\xf9\x05\xc5\x0f\x44\x06\xfd\x81\xff\x16\x14\xde\xae\x4f\xb7\xc5\x85\x98\x77\x47\x12\x82\x52\x11\x4e\xb6\xc4\xf5\x04\x25\x77\x63\xe1\x9e\x3c\xed\xa3\xd5\xfe\x47\xbe\xc3\x41\xfa\x85\xd1\x7e\x98\x72\x4e\xc3\x67\x3b\x1b\x21\xfb\x2a\xc5\x73\x83\x76\x85\x30\x0b\x33\xa2\x0e\xe2\xe8\xcd\x79\xc1\xd5\x61\x3b\xfb\x06\x16\x65\x02\xb1\x12\x72\xd7\xe4\x69\x45\x9c\xa6\x3d\xbf\xdd\x40\x27\x10\xae\x96\xea\x74\xcc\x8e\x77\x9a\xb6\x7b\x41\x27\x92\x70\xb5\xf4\x72\x73\x8a\xe9\x68\xdc\x98\x14\x54\xd0\x41\x32\xd8\x4b\x06\xf9\x0e\xa1\x2e\xdc\x2a\xb5\xb3\xdf\x7a\x7c\x01\xc1\x6d\x92\x24\x9e\x71\xa2\xaa\x0f\xf8\xb6\x11\x1e\xb2\x8a\x8f\x6f\x6f\x82\x61\xae\xec\xb3\x02\xc6\x58\x1f\xc6\x9c\x66\xab\xe5\xeb\x82\x73\x7a\xf3\x95\x85\x47\x03\x3f\xd2\xe2\x65\x07\xe0\x29\xfd\x89\xf1\x53\x5a\xae\xbd\x44\x36\xca\x20\x5b\xa3\x56\x37\xef\x07\xf7\xba\x36\x42\xbd\x28\xcc\x5a\xf0\x0d\x2c\xa0\x63\x6c\x2d\xdd\xb5\xad\x89\xe3\xc9\x8a\x0a\x84\x31\x7d\xa3\x6f\xaa\xd3\xe9\x91\x9a\x08\xa0\xd6\x62\x73\x14\x24\xe8\x23\x39\x11\x9d\x37\xc1\x54\xf2\xd1\x25\x23\x1c\xfc\xf0\xc8\xf5\x56\x4b\x75\x91\xf1\x79\x9a\x3e\x76\xbf\x8e\xc8\x37\xc0\xcb\xd5\xfc\x4f\xbc\x71\x48\x2b\x16\xdc\x42\xcf\x2a\x95\xa4\x2a\xf8\x69\x53\x34\x9a\x9b\x6a\xe9\x68\x82\xe6\x82\xbf\xd5\x22\xcf\x7d\xf4\x47\x35\xeb\xbf\xfc\x22\x03\x7c\xa6\x53\x07\x15\xb1\x44\x0b\x08\xf7\xa1\x7b\x1d\x87\xc8\x5e\x71\x46\xbf\xdd\x13\xff\x0c\x67\x1d\xab\x6d\x7d\x53\x1a\x7b\xd2\xb4\x02\xfe\xfe\x67\x63\xc2\x08\xc7\x1e\x35\xf7\x62\xbe\xf2\x4f\x32\xe5\x10\xd3\x1d\xf4\x9b\xde\xe5\xc3\x56\xcb\x64\xc2\x1e\xc8\x0f\x6e\x9d\x5b\xad\x37\x9e\x14\xaf\x20\x47\xd9\x33\x24\x49\xe7\x4b\xc6\x4f\x42\x31\x7c\x93\xa8\xdf\xc2\xa2\xec\xfe\x02\xc2\x1f\xa3\xef\xcc\xc8\x8b\xec\xbe\xd6\x83\x25\x0d\x15\x33\xaa\x26\xcb\xe9\x40\x1b\x27\x6a\xda\x1e\x16\xd9\x6a\x79\x46\xc6\x7e\x11\x04\x57\x8c\xb1\xc4\x33\xad\xf1\x1f\xc0\xf0\xf4\x27\x00\x00\xff\xff\x6c\x56\x09\x33\x6c\x0b\x00\x00")
func templateBuilderSetterTmplBytes() ([]byte, error) {
return bindataRead(
@@ -199,7 +199,7 @@ func templateBuilderSetterTmpl() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "template/builder/setter.tmpl", size: 2911, mode: os.FileMode(420), modTime: time.Unix(1564496459, 0)}
info := bindataFileInfo{name: "template/builder/setter.tmpl", size: 2924, mode: os.FileMode(420), modTime: time.Unix(1564665941, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}

View File

@@ -10,8 +10,8 @@
{{ $receiver }}.{{ $f.StructField }} = &{{ $p }}
return {{ $receiver }}
}
{{ if or $f.Optional $f.HasDefault }}
{{ $nillableFunc := print "SetNillable" (pascal $f.Name) }}
{{ if or $f.Optional $f.Nullable $f.HasDefault }}
{{ $nillableFunc := print "SetNillable" (pascal $f.Name) }}
// {{ $nillableFunc }} sets the {{ $f.Name }} field if the given value is not nil.
func ({{ $receiver }} *{{ $builder }}) {{ $nillableFunc }}({{ $p }} *{{ $f.Type }}) *{{ $builder }} {
if {{ $p }} != nil {