entc/gen: better formatted codegen for predicates (#336)

This commit is contained in:
Ariel Mashraki
2020-02-09 11:38:03 +02:00
committed by GitHub
parent 26440c2bc9
commit 9f9596c184
61 changed files with 3783 additions and 6660 deletions

View File

@@ -16,27 +16,23 @@ import (
// ID filters vertices based on their identifier.
func ID(id int) predicate.Card {
return predicate.Card(
func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
},
)
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
})
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
},
)
})
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldID), id))
},
)
})
}
// IDIn applies the In predicate on the ID field.
@@ -53,8 +49,7 @@ func IDIn(ids ...int) predicate.Card {
v[i] = ids[i]
}
s.Where(sql.In(s.C(FieldID), v...))
},
)
})
}
// IDNotIn applies the NotIn predicate on the ID field.
@@ -71,72 +66,63 @@ func IDNotIn(ids ...int) predicate.Card {
v[i] = ids[i]
}
s.Where(sql.NotIn(s.C(FieldID), v...))
},
)
})
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldID), id))
},
)
})
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldID), id))
},
)
})
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldID), id))
},
)
})
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldID), id))
},
)
})
}
// Expired applies equality check predicate on the "expired" field. It's identical to ExpiredEQ.
func Expired(v time.Time) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldExpired), v))
},
)
})
}
// Number applies equality check predicate on the "number" field. It's identical to NumberEQ.
func Number(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldNumber), v))
},
)
})
}
// ExpiredEQ applies the EQ predicate on the "expired" field.
func ExpiredEQ(v time.Time) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldExpired), v))
},
)
})
}
// ExpiredNEQ applies the NEQ predicate on the "expired" field.
func ExpiredNEQ(v time.Time) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldExpired), v))
},
)
})
}
// ExpiredIn applies the In predicate on the "expired" field.
@@ -153,8 +139,7 @@ func ExpiredIn(vs ...time.Time) predicate.Card {
return
}
s.Where(sql.In(s.C(FieldExpired), v...))
},
)
})
}
// ExpiredNotIn applies the NotIn predicate on the "expired" field.
@@ -171,56 +156,49 @@ func ExpiredNotIn(vs ...time.Time) predicate.Card {
return
}
s.Where(sql.NotIn(s.C(FieldExpired), v...))
},
)
})
}
// ExpiredGT applies the GT predicate on the "expired" field.
func ExpiredGT(v time.Time) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldExpired), v))
},
)
})
}
// ExpiredGTE applies the GTE predicate on the "expired" field.
func ExpiredGTE(v time.Time) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldExpired), v))
},
)
})
}
// ExpiredLT applies the LT predicate on the "expired" field.
func ExpiredLT(v time.Time) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldExpired), v))
},
)
})
}
// ExpiredLTE applies the LTE predicate on the "expired" field.
func ExpiredLTE(v time.Time) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldExpired), v))
},
)
})
}
// NumberEQ applies the EQ predicate on the "number" field.
func NumberEQ(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldNumber), v))
},
)
})
}
// NumberNEQ applies the NEQ predicate on the "number" field.
func NumberNEQ(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldNumber), v))
},
)
})
}
// NumberIn applies the In predicate on the "number" field.
@@ -237,8 +215,7 @@ func NumberIn(vs ...string) predicate.Card {
return
}
s.Where(sql.In(s.C(FieldNumber), v...))
},
)
})
}
// NumberNotIn applies the NotIn predicate on the "number" field.
@@ -255,80 +232,70 @@ func NumberNotIn(vs ...string) predicate.Card {
return
}
s.Where(sql.NotIn(s.C(FieldNumber), v...))
},
)
})
}
// NumberGT applies the GT predicate on the "number" field.
func NumberGT(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldNumber), v))
},
)
})
}
// NumberGTE applies the GTE predicate on the "number" field.
func NumberGTE(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldNumber), v))
},
)
})
}
// NumberLT applies the LT predicate on the "number" field.
func NumberLT(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldNumber), v))
},
)
})
}
// NumberLTE applies the LTE predicate on the "number" field.
func NumberLTE(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldNumber), v))
},
)
})
}
// NumberContains applies the Contains predicate on the "number" field.
func NumberContains(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.Contains(s.C(FieldNumber), v))
},
)
})
}
// NumberHasPrefix applies the HasPrefix predicate on the "number" field.
func NumberHasPrefix(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.HasPrefix(s.C(FieldNumber), v))
},
)
})
}
// NumberHasSuffix applies the HasSuffix predicate on the "number" field.
func NumberHasSuffix(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.HasSuffix(s.C(FieldNumber), v))
},
)
})
}
// NumberEqualFold applies the EqualFold predicate on the "number" field.
func NumberEqualFold(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.EqualFold(s.C(FieldNumber), v))
},
)
})
}
// NumberContainsFold applies the ContainsFold predicate on the "number" field.
func NumberContainsFold(v string) predicate.Card {
return predicate.Card(func(s *sql.Selector) {
s.Where(sql.ContainsFold(s.C(FieldNumber), v))
},
)
})
}
// HasOwner applies the HasEdge predicate on the "owner" edge.
@@ -340,8 +307,7 @@ func HasOwner() predicate.Card {
sqlgraph.Edge(sqlgraph.O2O, true, OwnerTable, OwnerColumn),
)
sqlgraph.HasNeighbors(s, step)
},
)
})
}
// HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates).
@@ -357,44 +323,37 @@ func HasOwnerWith(preds ...predicate.User) predicate.Card {
p(s)
}
})
},
)
})
}
// And groups list of predicates with the AND operator between them.
func And(predicates ...predicate.Card) predicate.Card {
return predicate.Card(
func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
},
)
return predicate.Card(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
})
}
// Or groups list of predicates with the OR operator between them.
func Or(predicates ...predicate.Card) predicate.Card {
return predicate.Card(
func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
p(s1)
return predicate.Card(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
s.Where(s1.P())
},
)
p(s1)
}
s.Where(s1.P())
})
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Card) predicate.Card {
return predicate.Card(
func(s *sql.Selector) {
p(s.Not())
},
)
return predicate.Card(func(s *sql.Selector) {
p(s.Not())
})
}

View File

@@ -14,27 +14,23 @@ import (
// ID filters vertices based on their identifier.
func ID(id int) predicate.User {
return predicate.User(
func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
},
)
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
})
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldID), id))
},
)
})
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldID), id))
},
)
})
}
// IDIn applies the In predicate on the ID field.
@@ -51,8 +47,7 @@ func IDIn(ids ...int) predicate.User {
v[i] = ids[i]
}
s.Where(sql.In(s.C(FieldID), v...))
},
)
})
}
// IDNotIn applies the NotIn predicate on the ID field.
@@ -69,72 +64,63 @@ func IDNotIn(ids ...int) predicate.User {
v[i] = ids[i]
}
s.Where(sql.NotIn(s.C(FieldID), v...))
},
)
})
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldID), id))
},
)
})
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldID), id))
},
)
})
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldID), id))
},
)
})
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldID), id))
},
)
})
}
// Age applies equality check predicate on the "age" field. It's identical to AgeEQ.
func Age(v int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldAge), v))
},
)
})
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldName), v))
},
)
})
}
// AgeEQ applies the EQ predicate on the "age" field.
func AgeEQ(v int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldAge), v))
},
)
})
}
// AgeNEQ applies the NEQ predicate on the "age" field.
func AgeNEQ(v int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldAge), v))
},
)
})
}
// AgeIn applies the In predicate on the "age" field.
@@ -151,8 +137,7 @@ func AgeIn(vs ...int) predicate.User {
return
}
s.Where(sql.In(s.C(FieldAge), v...))
},
)
})
}
// AgeNotIn applies the NotIn predicate on the "age" field.
@@ -169,56 +154,49 @@ func AgeNotIn(vs ...int) predicate.User {
return
}
s.Where(sql.NotIn(s.C(FieldAge), v...))
},
)
})
}
// AgeGT applies the GT predicate on the "age" field.
func AgeGT(v int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldAge), v))
},
)
})
}
// AgeGTE applies the GTE predicate on the "age" field.
func AgeGTE(v int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldAge), v))
},
)
})
}
// AgeLT applies the LT predicate on the "age" field.
func AgeLT(v int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldAge), v))
},
)
})
}
// AgeLTE applies the LTE predicate on the "age" field.
func AgeLTE(v int) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldAge), v))
},
)
})
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldName), v))
},
)
})
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldName), v))
},
)
})
}
// NameIn applies the In predicate on the "name" field.
@@ -235,8 +213,7 @@ func NameIn(vs ...string) predicate.User {
return
}
s.Where(sql.In(s.C(FieldName), v...))
},
)
})
}
// NameNotIn applies the NotIn predicate on the "name" field.
@@ -253,80 +230,70 @@ func NameNotIn(vs ...string) predicate.User {
return
}
s.Where(sql.NotIn(s.C(FieldName), v...))
},
)
})
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldName), v))
},
)
})
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldName), v))
},
)
})
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldName), v))
},
)
})
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldName), v))
},
)
})
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.Contains(s.C(FieldName), v))
},
)
})
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.HasPrefix(s.C(FieldName), v))
},
)
})
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.HasSuffix(s.C(FieldName), v))
},
)
})
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EqualFold(s.C(FieldName), v))
},
)
})
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.User {
return predicate.User(func(s *sql.Selector) {
s.Where(sql.ContainsFold(s.C(FieldName), v))
},
)
})
}
// HasCard applies the HasEdge predicate on the "card" edge.
@@ -338,8 +305,7 @@ func HasCard() predicate.User {
sqlgraph.Edge(sqlgraph.O2O, false, CardTable, CardColumn),
)
sqlgraph.HasNeighbors(s, step)
},
)
})
}
// HasCardWith applies the HasEdge predicate on the "card" edge with a given conditions (other predicates).
@@ -355,44 +321,37 @@ func HasCardWith(preds ...predicate.Card) predicate.User {
p(s)
}
})
},
)
})
}
// And groups list of predicates with the AND operator between them.
func And(predicates ...predicate.User) predicate.User {
return predicate.User(
func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
},
)
return predicate.User(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
})
}
// Or groups list of predicates with the OR operator between them.
func Or(predicates ...predicate.User) predicate.User {
return predicate.User(
func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
p(s1)
return predicate.User(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
s.Where(s1.P())
},
)
p(s1)
}
s.Where(s1.P())
})
}
// Not applies the not operator on the given predicate.
func Not(p predicate.User) predicate.User {
return predicate.User(
func(s *sql.Selector) {
p(s.Not())
},
)
return predicate.User(func(s *sql.Selector) {
p(s.Not())
})
}