entc: add idtype option codegen

Reviewed By: alexsn

Differential Revision: D16601757

fbshipit-source-id: 35d5fbfb4ef40bae192e084ad4e067880175e71c
This commit is contained in:
Ariel Mashraki
2019-08-04 03:08:47 -07:00
committed by Facebook Github Bot
parent c203f043cf
commit 2cc8286f5f
41 changed files with 302 additions and 339 deletions

View File

@@ -26,7 +26,7 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) (*{{ $.Name
if err != nil {
return nil, rollback(tx, err)
}
{{ $.Receiver }}.ID = {{ if $.ID.IsString }}strconv.FormatInt(id, 10){{ else }}id{{ end }}
{{ $.Receiver }}.ID = {{ if $.ID.IsString }}strconv.FormatInt(id, 10){{ else }}int(id){{ end }}
{{- range $_, $e := $.Edges }}
if len({{ $receiver }}.{{ $e.StructField }}) > 0 {
{{- if and $e.Unique $e.SelfRef }}{{/* O2O with self reference */}}

View File

@@ -21,9 +21,9 @@
{{ if $.ID.IsString }}v[i], _ = strconv.Atoi({{ $arg }}[i]){{ else }}v[i] = {{ $arg }}[i]{{ end }}
}
{{- else if $.ID.IsString }}
v, _ := strconv.Atoi({{ $arg }})
id, _ := strconv.Atoi({{ $arg }})
{{- end }}
s.Where(sql.{{ $op.Name }}(s.C({{ $.ID.Constant }}), v{{ if $op.Variadic }}...{{ end }}))
s.Where(sql.{{ $op.Name }}(s.C({{ $.ID.Constant }}), {{ if $op.Variadic }}v...{{ else }}id{{ end }}))
}
{{- end }}