mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: suffix Order and Aggregate with Func (#449)
This commit is contained in:
@@ -25,7 +25,7 @@ type CarQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []Order
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.Car
|
||||
// eager-loading edges.
|
||||
@@ -55,7 +55,7 @@ func (cq *CarQuery) Offset(offset int) *CarQuery {
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (cq *CarQuery) Order(o ...Order) *CarQuery {
|
||||
func (cq *CarQuery) Order(o ...OrderFunc) *CarQuery {
|
||||
cq.order = append(cq.order, o...)
|
||||
return cq
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func (cq *CarQuery) Clone() *CarQuery {
|
||||
config: cq.config,
|
||||
limit: cq.limit,
|
||||
offset: cq.offset,
|
||||
order: append([]Order{}, cq.order...),
|
||||
order: append([]OrderFunc{}, cq.order...),
|
||||
unique: append([]string{}, cq.unique...),
|
||||
predicates: append([]predicate.Car{}, cq.predicates...),
|
||||
// clone intermediate query.
|
||||
@@ -475,14 +475,14 @@ func (cq *CarQuery) sqlQuery() *sql.Selector {
|
||||
type CarGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (cgb *CarGroupBy) Aggregate(fns ...Aggregate) *CarGroupBy {
|
||||
func (cgb *CarGroupBy) Aggregate(fns ...AggregateFunc) *CarGroupBy {
|
||||
cgb.fns = append(cgb.fns, fns...)
|
||||
return cgb
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ type (
|
||||
MutateFunc = ent.MutateFunc
|
||||
)
|
||||
|
||||
// Order applies an ordering on either graph traversal or sql selector.
|
||||
type Order func(*sql.Selector)
|
||||
// OrderFunc applies an ordering on either graph traversal or sql selector.
|
||||
type OrderFunc func(*sql.Selector)
|
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) Order {
|
||||
func Asc(fields ...string) OrderFunc {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
s.OrderBy(sql.Asc(f))
|
||||
@@ -43,7 +43,7 @@ func Asc(fields ...string) Order {
|
||||
}
|
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) Order {
|
||||
func Desc(fields ...string) OrderFunc {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
s.OrderBy(sql.Desc(f))
|
||||
@@ -51,8 +51,8 @@ func Desc(fields ...string) Order {
|
||||
}
|
||||
}
|
||||
|
||||
// Aggregate applies an aggregation step on the group-by traversal/selector.
|
||||
type Aggregate func(*sql.Selector) string
|
||||
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||
type AggregateFunc func(*sql.Selector) string
|
||||
|
||||
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||
//
|
||||
@@ -60,42 +60,42 @@ type Aggregate func(*sql.Selector) string
|
||||
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func As(fn Aggregate, end string) Aggregate {
|
||||
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.As(fn(s), end)
|
||||
}
|
||||
}
|
||||
|
||||
// Count applies the "count" aggregation function on each group.
|
||||
func Count() Aggregate {
|
||||
func Count() AggregateFunc {
|
||||
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 {
|
||||
func Max(field string) AggregateFunc {
|
||||
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 {
|
||||
func Mean(field string) AggregateFunc {
|
||||
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 {
|
||||
func Min(field string) AggregateFunc {
|
||||
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 {
|
||||
func Sum(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Sum(s.C(field))
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ type GroupQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []Order
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.Group
|
||||
// eager-loading edges.
|
||||
@@ -55,7 +55,7 @@ func (gq *GroupQuery) Offset(offset int) *GroupQuery {
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (gq *GroupQuery) Order(o ...Order) *GroupQuery {
|
||||
func (gq *GroupQuery) Order(o ...OrderFunc) *GroupQuery {
|
||||
gq.order = append(gq.order, o...)
|
||||
return gq
|
||||
}
|
||||
@@ -248,7 +248,7 @@ func (gq *GroupQuery) Clone() *GroupQuery {
|
||||
config: gq.config,
|
||||
limit: gq.limit,
|
||||
offset: gq.offset,
|
||||
order: append([]Order{}, gq.order...),
|
||||
order: append([]OrderFunc{}, gq.order...),
|
||||
unique: append([]string{}, gq.unique...),
|
||||
predicates: append([]predicate.Group{}, gq.predicates...),
|
||||
// clone intermediate query.
|
||||
@@ -503,14 +503,14 @@ func (gq *GroupQuery) sqlQuery() *sql.Selector {
|
||||
type GroupGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (ggb *GroupGroupBy) Aggregate(fns ...Aggregate) *GroupGroupBy {
|
||||
func (ggb *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy {
|
||||
ggb.fns = append(ggb.fns, fns...)
|
||||
return ggb
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type UserQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
order []Order
|
||||
order []OrderFunc
|
||||
unique []string
|
||||
predicates []predicate.User
|
||||
// eager-loading edges.
|
||||
@@ -57,7 +57,7 @@ func (uq *UserQuery) Offset(offset int) *UserQuery {
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (uq *UserQuery) Order(o ...Order) *UserQuery {
|
||||
func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery {
|
||||
uq.order = append(uq.order, o...)
|
||||
return uq
|
||||
}
|
||||
@@ -268,7 +268,7 @@ func (uq *UserQuery) Clone() *UserQuery {
|
||||
config: uq.config,
|
||||
limit: uq.limit,
|
||||
offset: uq.offset,
|
||||
order: append([]Order{}, uq.order...),
|
||||
order: append([]OrderFunc{}, uq.order...),
|
||||
unique: append([]string{}, uq.unique...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
// clone intermediate query.
|
||||
@@ -563,14 +563,14 @@ func (uq *UserQuery) sqlQuery() *sql.Selector {
|
||||
type UserGroupBy struct {
|
||||
config
|
||||
fields []string
|
||||
fns []Aggregate
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (ugb *UserGroupBy) Aggregate(fns ...Aggregate) *UserGroupBy {
|
||||
func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy {
|
||||
ugb.fns = append(ugb.fns, fns...)
|
||||
return ugb
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user