Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee0d994

Browse files
committed
entc/gen: allow using 'client' and 'tx' as schema field names
1 parent 366aaaa commit ee0d994

File tree

10 files changed

+373
-9
lines changed

10 files changed

+373
-9
lines changed

entc/gen/type.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,11 @@ func (f Field) EntSQL() *entsql.Annotation {
10331033
}
10341034

10351035
// mutMethods returns the method names of mutation interface.
1036-
var mutMethods = func() map[string]struct{} {
1036+
var mutMethods = func() map[string]bool {
1037+
names := map[string]bool{"Client": true, "Tx": true, "Where": true}
10371038
t := reflect.TypeOf(new(ent.Mutation)).Elem()
1038-
names := make(map[string]struct{})
10391039
for i := 0; i < t.NumMethod(); i++ {
1040-
names[t.Method(i).Name] = struct{}{}
1040+
names[t.Method(i).Name] = true
10411041
}
10421042
return names
10431043
}()
@@ -1047,7 +1047,7 @@ var mutMethods = func() map[string]struct{} {
10471047
// with the mutation methods, prefix the method with "Get".
10481048
func (f Field) MutationGet() string {
10491049
name := pascal(f.Name)
1050-
if _, ok := mutMethods[name]; ok {
1050+
if mutMethods[name] {
10511051
name = "Get" + name
10521052
}
10531053
return name
@@ -1056,7 +1056,7 @@ func (f Field) MutationGet() string {
10561056
// MutationGetOld returns the method name for getting the old value of a field.
10571057
func (f Field) MutationGetOld() string {
10581058
name := "Old" + pascal(f.Name)
1059-
if _, ok := mutMethods[name]; ok {
1059+
if mutMethods[name] {
10601060
name = "Get" + name
10611061
}
10621062
return name
@@ -1067,7 +1067,7 @@ func (f Field) MutationGetOld() string {
10671067
// with the mutation methods, suffix the method with "Field".
10681068
func (f Field) MutationReset() string {
10691069
name := "Reset" + pascal(f.Name)
1070-
if _, ok := mutMethods[name]; ok {
1070+
if mutMethods[name] {
10711071
name += "Field"
10721072
}
10731073
return name
@@ -1078,7 +1078,7 @@ func (f Field) MutationReset() string {
10781078
// with the mutation methods, suffix the method with "Field".
10791079
func (f Field) MutationSet() string {
10801080
name := "Set" + f.StructField()
1081-
if _, ok := mutMethods[name]; ok {
1081+
if mutMethods[name] {
10821082
name += "Field"
10831083
}
10841084
return name

entc/integration/ent/comment.go

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entc/integration/ent/comment/comment.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entc/integration/ent/comment/where.go

Lines changed: 120 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entc/integration/ent/comment_create.go

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)