entc/gen: minor imporvements to make goimports work easier (#3106)

This commit is contained in:
Ariel Mashraki
2022-11-18 22:54:17 +02:00
committed by GitHub
parent da9322fd2e
commit 4dd6b5bb74
2 changed files with 7 additions and 4 deletions

View File

@@ -52,6 +52,7 @@ var drivers = []*Storage{
Builder: reflect.TypeOf(&sql.Selector{}),
Dialects: []string{"dialect.SQLite", "dialect.MySQL", "dialect.Postgres"},
Imports: []string{
"database/sql/driver",
"entgo.io/ent/dialect/sql",
"entgo.io/ent/dialect/sql/sqlgraph",
"entgo.io/ent/dialect/sql/sqljson",

View File

@@ -14,13 +14,13 @@ import (
"math"
"strings"
"time"
{{- /* Ignore generting on graph specififc templates */}}
{{- if not (eq $.Config.Package $.Package) }}
{{- /* Ignore generting on graph templates (e.g. config.tmpl, client.tmpl, etc). */}}
{{- if ne $.Config.Package $.Package }}
"{{ $.Config.Package }}/predicate"
{{- if $.HasOneFieldID }}
{{- with $.ID.Type.PkgPath }}
{{- $name := $.ID.Type.PkgName }}
{{ if ne $name (base $.ID.Type.PkgPath) }}{{ $name }} {{ end}}"{{ . }}"
{{ if ne $name (base $.ID.Type.PkgPath) }}{{ $name }} {{ end }}"{{ . }}"
{{- end }}
{{- end }}
{{- /* Import external packages */}}
@@ -39,12 +39,14 @@ import (
{{/* A template for importing fields with custom types */}}
{{ define "import/types" -}}
{{- $seen := dict }}
{{- $fields := $.Fields }}{{ if $.HasOneFieldID }}{{ if $.ID.UserDefined }}{{ $fields = append $fields $.ID }}{{ end }}{{ end }}
{{- range $f := $fields }}
{{- $pkg := $f.Type.PkgPath }}
{{- if and $pkg (not (hasImport (base $pkg))) }}
{{- if and $pkg (not (hasImport (base $pkg))) (not (hasKey $seen $pkg)) }}
{{- $name := $f.Type.PkgName }}
{{ if ne $name (base $pkg) }}{{ $name }} {{ end}}"{{ $pkg }}"
{{- $seen = set $seen $pkg true }}
{{- end }}
{{- end }}
{{- end }}