entc/gen: remove multi storage support

This commit is contained in:
Ariel Mashraki
2019-12-13 17:20:06 +02:00
parent 1311f5f2f2
commit e85b10be36
226 changed files with 35018 additions and 15853 deletions

View File

@@ -50,7 +50,6 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error)
return nil, err
}
return NewClient(append(options, Driver(drv))...), nil
default:
return nil, fmt.Errorf("unsupported driver: %q", driverName)
}

View File

@@ -20,31 +20,24 @@ type Order func(*sql.Selector)
// Asc applies the given fields in ASC order.
func Asc(fields ...string) Order {
return Order(
func(s *sql.Selector) {
for _, f := range fields {
s.OrderBy(sql.Asc(f))
}
},
)
return func(s *sql.Selector) {
for _, f := range fields {
s.OrderBy(sql.Asc(f))
}
}
}
// Desc applies the given fields in DESC order.
func Desc(fields ...string) Order {
return Order(
func(s *sql.Selector) {
for _, f := range fields {
s.OrderBy(sql.Desc(f))
}
},
)
return func(s *sql.Selector) {
for _, f := range fields {
s.OrderBy(sql.Desc(f))
}
}
}
// Aggregate applies an aggregation step on the group-by traversal/selector.
type Aggregate struct {
// SQL the column wrapped with the aggregation function.
SQL func(*sql.Selector) string
}
type Aggregate func(*sql.Selector) string
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
//
@@ -53,55 +46,43 @@ type Aggregate struct {
// Scan(ctx, &v)
//
func As(fn Aggregate, end string) Aggregate {
return Aggregate{
SQL: func(s *sql.Selector) string {
return sql.As(fn.SQL(s), end)
},
return func(s *sql.Selector) string {
return sql.As(fn(s), end)
}
}
// Count applies the "count" aggregation function on each group.
func Count() Aggregate {
return Aggregate{
SQL: func(s *sql.Selector) string {
return sql.Count("*")
},
return func(s *sql.Selector) string {
return sql.Count("*")
}
}
// Max applies the "max" aggregation function on the given field of each group.
func Max(field string) Aggregate {
return Aggregate{
SQL: func(s *sql.Selector) string {
return sql.Max(s.C(field))
},
return func(s *sql.Selector) string {
return sql.Max(s.C(field))
}
}
// Mean applies the "mean" aggregation function on the given field of each group.
func Mean(field string) Aggregate {
return Aggregate{
SQL: func(s *sql.Selector) string {
return sql.Avg(s.C(field))
},
return func(s *sql.Selector) string {
return sql.Avg(s.C(field))
}
}
// Min applies the "min" aggregation function on the given field of each group.
func Min(field string) Aggregate {
return Aggregate{
SQL: func(s *sql.Selector) string {
return sql.Min(s.C(field))
},
return func(s *sql.Selector) string {
return sql.Min(s.C(field))
}
}
// Sum applies the "sum" aggregation function on the given field of each group.
func Sum(field string) Aggregate {
return Aggregate{
SQL: func(s *sql.Selector) string {
return sql.Sum(s.C(field))
},
return func(s *sql.Selector) string {
return sql.Sum(s.C(field))
}
}

View File

@@ -22,120 +22,109 @@ func ID(id uint64) predicate.User {
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id uint64) 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))
},
)
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id uint64) predicate.User {
return predicate.User(
func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldID), id))
},
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldID), id))
},
)
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...uint64) predicate.User {
return predicate.User(
func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(ids) == 0 {
s.Where(sql.False())
return
}
v := make([]interface{}, len(ids))
for i := range v {
v[i] = ids[i]
}
s.Where(sql.In(s.C(FieldID), v...))
},
return predicate.User(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(ids) == 0 {
s.Where(sql.False())
return
}
v := make([]interface{}, len(ids))
for i := range v {
v[i] = ids[i]
}
s.Where(sql.In(s.C(FieldID), v...))
},
)
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...uint64) predicate.User {
return predicate.User(
func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(ids) == 0 {
s.Where(sql.False())
return
}
v := make([]interface{}, len(ids))
for i := range v {
v[i] = ids[i]
}
s.Where(sql.NotIn(s.C(FieldID), v...))
},
return predicate.User(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(ids) == 0 {
s.Where(sql.False())
return
}
v := make([]interface{}, len(ids))
for i := range v {
v[i] = ids[i]
}
s.Where(sql.NotIn(s.C(FieldID), v...))
},
)
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id uint64) predicate.User {
return predicate.User(
func(s *sql.Selector) {
s.Where(sql.GT(s.C(FieldID), id))
},
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 uint64) predicate.User {
return predicate.User(
func(s *sql.Selector) {
s.Where(sql.GTE(s.C(FieldID), id))
},
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 uint64) predicate.User {
return predicate.User(
func(s *sql.Selector) {
s.Where(sql.LT(s.C(FieldID), id))
},
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 uint64) predicate.User {
return predicate.User(
func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldID), id))
},
return predicate.User(func(s *sql.Selector) {
s.Where(sql.LTE(s.C(FieldID), id))
},
)
}
// 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))
},
return predicate.User(func(s *sql.Selector) {
s.Where(sql.EQ(s.C(FieldName), 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))
},
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))
},
return predicate.User(func(s *sql.Selector) {
s.Where(sql.NEQ(s.C(FieldName), v))
},
)
}
@@ -145,16 +134,15 @@ func NameIn(vs ...string) predicate.User {
for i := range v {
v[i] = vs[i]
}
return predicate.User(
func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(vs) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldName), v...))
},
return predicate.User(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(vs) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.In(s.C(FieldName), v...))
},
)
}
@@ -164,193 +152,177 @@ func NameNotIn(vs ...string) predicate.User {
for i := range v {
v[i] = vs[i]
}
return predicate.User(
func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(vs) == 0 {
s.Where(sql.False())
return
}
s.Where(sql.NotIn(s.C(FieldName), v...))
},
return predicate.User(func(s *sql.Selector) {
// if not arguments were provided, append the FALSE constants,
// since we can't apply "IN ()". This will make this predicate falsy.
if len(vs) == 0 {
s.Where(sql.False())
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))
},
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))
},
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))
},
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))
},
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))
},
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))
},
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))
},
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))
},
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))
},
return predicate.User(func(s *sql.Selector) {
s.Where(sql.ContainsFold(s.C(FieldName), v))
},
)
}
// HasSpouse applies the HasEdge predicate on the "spouse" edge.
func HasSpouse() predicate.User {
return predicate.User(
func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(SpouseTable, FieldID),
sql.Edge(sql.O2O, false, SpouseTable, SpouseColumn),
)
sql.HasNeighbors(s, step)
},
return predicate.User(func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(SpouseTable, FieldID),
sql.Edge(sql.O2O, false, SpouseTable, SpouseColumn),
)
sql.HasNeighbors(s, step)
},
)
}
// HasSpouseWith applies the HasEdge predicate on the "spouse" edge with a given conditions (other predicates).
func HasSpouseWith(preds ...predicate.User) predicate.User {
return predicate.User(
func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(Table, FieldID),
sql.Edge(sql.O2O, false, SpouseTable, SpouseColumn),
)
sql.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
},
return predicate.User(func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(Table, FieldID),
sql.Edge(sql.O2O, false, SpouseTable, SpouseColumn),
)
sql.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
},
)
}
// HasFollowers applies the HasEdge predicate on the "followers" edge.
func HasFollowers() predicate.User {
return predicate.User(
func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(FollowersTable, FieldID),
sql.Edge(sql.M2M, true, FollowersTable, FollowersPrimaryKey...),
)
sql.HasNeighbors(s, step)
},
return predicate.User(func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(FollowersTable, FieldID),
sql.Edge(sql.M2M, true, FollowersTable, FollowersPrimaryKey...),
)
sql.HasNeighbors(s, step)
},
)
}
// HasFollowersWith applies the HasEdge predicate on the "followers" edge with a given conditions (other predicates).
func HasFollowersWith(preds ...predicate.User) predicate.User {
return predicate.User(
func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(Table, FieldID),
sql.Edge(sql.M2M, true, FollowersTable, FollowersPrimaryKey...),
)
sql.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
},
return predicate.User(func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(Table, FieldID),
sql.Edge(sql.M2M, true, FollowersTable, FollowersPrimaryKey...),
)
sql.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
},
)
}
// HasFollowing applies the HasEdge predicate on the "following" edge.
func HasFollowing() predicate.User {
return predicate.User(
func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(FollowingTable, FieldID),
sql.Edge(sql.M2M, false, FollowingTable, FollowingPrimaryKey...),
)
sql.HasNeighbors(s, step)
},
return predicate.User(func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(FollowingTable, FieldID),
sql.Edge(sql.M2M, false, FollowingTable, FollowingPrimaryKey...),
)
sql.HasNeighbors(s, step)
},
)
}
// HasFollowingWith applies the HasEdge predicate on the "following" edge with a given conditions (other predicates).
func HasFollowingWith(preds ...predicate.User) predicate.User {
return predicate.User(
func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(Table, FieldID),
sql.Edge(sql.M2M, false, FollowingTable, FollowingPrimaryKey...),
)
sql.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
},
return predicate.User(func(s *sql.Selector) {
step := sql.NewStep(
sql.From(Table, FieldID),
sql.To(Table, FieldID),
sql.Edge(sql.M2M, false, FollowingTable, FollowingPrimaryKey...),
)
sql.HasNeighborsWith(s, step, func(s *sql.Selector) {
for _, p := range preds {
p(s)
}
})
},
)
}

View File

@@ -25,7 +25,7 @@ type UserQuery struct {
order []Order
unique []string
predicates []predicate.User
// intermediate queries.
// intermediate query.
sql *sql.Selector
}
@@ -253,7 +253,7 @@ func (uq *UserQuery) Clone() *UserQuery {
order: append([]Order{}, uq.order...),
unique: append([]string{}, uq.unique...),
predicates: append([]predicate.User{}, uq.predicates...),
// clone intermediate queries.
// clone intermediate query.
sql: uq.sql.Clone(),
}
}
@@ -379,7 +379,7 @@ type UserGroupBy struct {
config
fields []string
fns []Aggregate
// intermediate queries.
// intermediate query.
sql *sql.Selector
}
@@ -500,7 +500,7 @@ func (ugb *UserGroupBy) sqlQuery() *sql.Selector {
columns := make([]string, 0, len(ugb.fields)+len(ugb.fns))
columns = append(columns, ugb.fields...)
for _, fn := range ugb.fns {
columns = append(columns, fn.SQL(selector))
columns = append(columns, fn(selector))
}
return selector.Select(columns...).GroupBy(ugb.fields...)
}