mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
all: move sqlgraph to its own package
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/facebookincubator/ent/dialect"
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
// Client is the client that holds all ent builders.
|
||||
@@ -54,7 +55,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)
|
||||
}
|
||||
@@ -170,12 +170,12 @@ func (c *GroupClient) GetX(ctx context.Context, id int) *Group {
|
||||
func (c *GroupClient) QueryUsers(gr *Group) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
id := gr.ID
|
||||
step := sql.NewStep(
|
||||
sql.From(group.Table, group.FieldID, id),
|
||||
sql.To(user.Table, user.FieldID),
|
||||
sql.Edge(sql.M2M, false, group.UsersTable, group.UsersPrimaryKey...),
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, group.UsersTable, group.UsersPrimaryKey...),
|
||||
)
|
||||
query.sql = sql.Neighbors(gr.driver.Dialect(), step)
|
||||
query.sql = sqlgraph.Neighbors(gr.driver.Dialect(), step)
|
||||
|
||||
return query
|
||||
}
|
||||
@@ -248,12 +248,12 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User {
|
||||
func (c *UserClient) QueryGroups(u *User) *GroupQuery {
|
||||
query := &GroupQuery{config: c.config}
|
||||
id := u.ID
|
||||
step := sql.NewStep(
|
||||
sql.From(user.Table, user.FieldID, id),
|
||||
sql.To(group.Table, group.FieldID),
|
||||
sql.Edge(sql.M2M, true, user.GroupsTable, user.GroupsPrimaryKey...),
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(group.Table, group.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, user.GroupsTable, user.GroupsPrimaryKey...),
|
||||
)
|
||||
query.sql = sql.Neighbors(u.driver.Dialect(), step)
|
||||
query.sql = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package group
|
||||
|
||||
import (
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebookincubator/ent/examples/m2m2types/ent/predicate"
|
||||
)
|
||||
|
||||
@@ -22,120 +23,109 @@ func ID(id int) predicate.Group {
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Group {
|
||||
return predicate.Group(
|
||||
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.Group(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 ...int) predicate.Group {
|
||||
return predicate.Group(
|
||||
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.Group(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 int) predicate.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldName), v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -145,16 +135,15 @@ func NameIn(vs ...string) predicate.Group {
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Group(
|
||||
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.Group(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,129 +153,117 @@ func NameNotIn(vs ...string) predicate.Group {
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Group(
|
||||
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.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.Contains(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.HasPrefix(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.HasSuffix(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.EqualFold(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(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.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldName), v))
|
||||
},
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
s.Where(sql.ContainsFold(s.C(FieldName), v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// HasUsers applies the HasEdge predicate on the "users" edge.
|
||||
func HasUsers() predicate.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
step := sql.NewStep(
|
||||
sql.From(Table, FieldID),
|
||||
sql.To(UsersTable, FieldID),
|
||||
sql.Edge(sql.M2M, false, UsersTable, UsersPrimaryKey...),
|
||||
)
|
||||
sql.HasNeighbors(s, step)
|
||||
},
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UsersTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, UsersTable, UsersPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// HasUsersWith applies the HasEdge predicate on the "users" edge with a given conditions (other predicates).
|
||||
func HasUsersWith(preds ...predicate.User) predicate.Group {
|
||||
return predicate.Group(
|
||||
func(s *sql.Selector) {
|
||||
step := sql.NewStep(
|
||||
sql.From(Table, FieldID),
|
||||
sql.To(UsersInverseTable, FieldID),
|
||||
sql.Edge(sql.M2M, false, UsersTable, UsersPrimaryKey...),
|
||||
)
|
||||
sql.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
},
|
||||
return predicate.Group(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UsersInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, UsersTable, UsersPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebookincubator/ent/examples/m2m2types/ent/group"
|
||||
"github.com/facebookincubator/ent/examples/m2m2types/ent/predicate"
|
||||
"github.com/facebookincubator/ent/examples/m2m2types/ent/user"
|
||||
@@ -26,7 +27,7 @@ type GroupQuery struct {
|
||||
order []Order
|
||||
unique []string
|
||||
predicates []predicate.Group
|
||||
// intermediate queries.
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
@@ -57,12 +58,12 @@ func (gq *GroupQuery) Order(o ...Order) *GroupQuery {
|
||||
// QueryUsers chains the current query on the users edge.
|
||||
func (gq *GroupQuery) QueryUsers() *UserQuery {
|
||||
query := &UserQuery{config: gq.config}
|
||||
step := sql.NewStep(
|
||||
sql.From(group.Table, group.FieldID, gq.sqlQuery()),
|
||||
sql.To(user.Table, user.FieldID),
|
||||
sql.Edge(sql.M2M, false, group.UsersTable, group.UsersPrimaryKey...),
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, gq.sqlQuery()),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, group.UsersTable, group.UsersPrimaryKey...),
|
||||
)
|
||||
query.sql = sql.SetNeighbors(gq.driver.Dialect(), step)
|
||||
query.sql = sqlgraph.SetNeighbors(gq.driver.Dialect(), step)
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -230,7 +231,7 @@ func (gq *GroupQuery) Clone() *GroupQuery {
|
||||
order: append([]Order{}, gq.order...),
|
||||
unique: append([]string{}, gq.unique...),
|
||||
predicates: append([]predicate.Group{}, gq.predicates...),
|
||||
// clone intermediate queries.
|
||||
// clone intermediate query.
|
||||
sql: gq.sql.Clone(),
|
||||
}
|
||||
}
|
||||
@@ -356,7 +357,7 @@ type GroupGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate queries.
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
@@ -477,7 +478,7 @@ func (ggb *GroupGroupBy) sqlQuery() *sql.Selector {
|
||||
columns := make([]string, 0, len(ggb.fields)+len(ggb.fns))
|
||||
columns = append(columns, ggb.fields...)
|
||||
for _, fn := range ggb.fns {
|
||||
columns = append(columns, fn.SQL(selector))
|
||||
columns = append(columns, fn(selector))
|
||||
}
|
||||
return selector.Select(columns...).GroupBy(ggb.fields...)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package user
|
||||
|
||||
import (
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebookincubator/ent/examples/m2m2types/ent/predicate"
|
||||
)
|
||||
|
||||
@@ -22,129 +23,117 @@ func ID(id int) predicate.User {
|
||||
|
||||
// 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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
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 ...int) 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 ...int) 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 int) 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 int) 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 int) 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 int) 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))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// 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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldAge), v))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -154,16 +143,15 @@ func AgeIn(vs ...int) 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(FieldAge), 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(FieldAge), v...))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -173,70 +161,63 @@ func AgeNotIn(vs ...int) 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(FieldAge), 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(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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
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))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -246,16 +227,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...))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -265,129 +245,117 @@ 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))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// HasGroups applies the HasEdge predicate on the "groups" edge.
|
||||
func HasGroups() predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
step := sql.NewStep(
|
||||
sql.From(Table, FieldID),
|
||||
sql.To(GroupsTable, FieldID),
|
||||
sql.Edge(sql.M2M, true, GroupsTable, GroupsPrimaryKey...),
|
||||
)
|
||||
sql.HasNeighbors(s, step)
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(GroupsTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, GroupsTable, GroupsPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// HasGroupsWith applies the HasEdge predicate on the "groups" edge with a given conditions (other predicates).
|
||||
func HasGroupsWith(preds ...predicate.Group) predicate.User {
|
||||
return predicate.User(
|
||||
func(s *sql.Selector) {
|
||||
step := sql.NewStep(
|
||||
sql.From(Table, FieldID),
|
||||
sql.To(GroupsInverseTable, FieldID),
|
||||
sql.Edge(sql.M2M, true, GroupsTable, GroupsPrimaryKey...),
|
||||
)
|
||||
sql.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
},
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(GroupsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, GroupsTable, GroupsPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
||||
"github.com/facebookincubator/ent/examples/m2m2types/ent/group"
|
||||
"github.com/facebookincubator/ent/examples/m2m2types/ent/predicate"
|
||||
"github.com/facebookincubator/ent/examples/m2m2types/ent/user"
|
||||
@@ -26,7 +27,7 @@ type UserQuery struct {
|
||||
order []Order
|
||||
unique []string
|
||||
predicates []predicate.User
|
||||
// intermediate queries.
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
@@ -57,12 +58,12 @@ func (uq *UserQuery) Order(o ...Order) *UserQuery {
|
||||
// QueryGroups chains the current query on the groups edge.
|
||||
func (uq *UserQuery) QueryGroups() *GroupQuery {
|
||||
query := &GroupQuery{config: uq.config}
|
||||
step := sql.NewStep(
|
||||
sql.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sql.To(group.Table, group.FieldID),
|
||||
sql.Edge(sql.M2M, true, user.GroupsTable, user.GroupsPrimaryKey...),
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, uq.sqlQuery()),
|
||||
sqlgraph.To(group.Table, group.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, user.GroupsTable, user.GroupsPrimaryKey...),
|
||||
)
|
||||
query.sql = sql.SetNeighbors(uq.driver.Dialect(), step)
|
||||
query.sql = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return query
|
||||
}
|
||||
|
||||
@@ -230,7 +231,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(),
|
||||
}
|
||||
}
|
||||
@@ -356,7 +357,7 @@ type UserGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
// intermediate queries.
|
||||
// intermediate query.
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
@@ -477,7 +478,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...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user