entc/gen: support setting GoType for integer IDs (#2657)

* Fix problem when model maps integer id to a GoType

* Update generated files

* apply suggestions from code review

* Update generated files

* Update generated files after merge from master

* Cleanup test code in integration

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* Modify integration test IntSID.

Wrapped tests of IntSID for avoid conflicts.

* Modify tests in integrations

Order of tests was changed. As a result, if-statement for difference in RDB is deleted.

+ force pushing same commit to invoke ci.

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
Reiji Tokuda
2022-07-04 13:50:51 +08:00
committed by GitHub
parent ed783dba70
commit 91b643091f
20 changed files with 3024 additions and 19 deletions

View File

@@ -180,7 +180,13 @@ func ({{ $receiver }} *{{ $builder }}) Save(ctx context.Context) ([]*{{ $.Name }
{{- if $.HasOneFieldID }}
mutation.{{ $.ID.BuilderField }} = &nodes[i].{{ $.ID.StructField }}
{{- if or $.ID.IsString $.ID.IsUUID $.ID.IsBytes $.ID.IsOther }}
{{- /* Do nothing, because these 2 types must be supplied by the user. */ -}}
{{- /* Do nothing, because these 4 types must be supplied by the user. */ -}}
{{- else if or $.ID.Type.ValueScanner }}
if specs[i].ID.Value != nil {
if err := nodes[i].ID.Scan(specs[i].ID.Value); err != nil {
return nil, err
}
}
{{- else }}
if specs[i].ID.Value != nil {{ if $.ID.UserDefined }}&& nodes[i].ID == 0{{ end }} {
id := specs[i].ID.Value.(int64)

View File

@@ -55,7 +55,7 @@ func ({{ $receiver }} *{{ $.Name }}) assignValues(columns []string, values []int
switch columns[{{ $idx }}] {
{{- if $.HasOneFieldID }}
case {{ $.Package }}.{{ $.ID.Constant }}:
{{- if or $.ID.IsString $.ID.IsUUID $.ID.IsBytes $.ID.IsOther }}
{{- if or $.ID.IsString $.ID.IsBytes $.ID.HasGoType }}
{{- with extend $ "Idx" $idx "Field" $.ID "Rec" $receiver }}
{{ template "dialect/sql/decode/field" . }}
{{- end }}
@@ -76,7 +76,7 @@ func ({{ $receiver }} *{{ $.Name }}) assignValues(columns []string, values []int
{{- range $i, $fk := $.UnexportedForeignKeys }}
{{- $f := $fk.Field }}
case {{ if $fk.UserDefined }}{{ $.Package }}.{{ $.ID.Constant }}{{ else }}{{ $.Package }}.ForeignKeys[{{ $i }}]{{ end }}:
{{- if or $fk.UserDefined (and $f.UserDefined (or $f.IsString $f.IsUUID $f.IsBytes $f.IsOther)) }}
{{- if or $fk.UserDefined (and $f.UserDefined (or $f.IsString $f.IsBytes $f.HasGoType)) }}
{{- with extend $ "Idx" $idx "Field" $f "Rec" $receiver "StructField" $fk.StructField }}
{{ template "dialect/sql/decode/field" . }}
{{- end }}