mirror of
https://github.com/ent/ent.git
synced 2026-03-05 19:35:23 +03:00
entc: update groupReceiver and selectReceiver (#4395)
* update GroupReceiver and SelectReceiver * update examples * update entc/integration generated code * Update entc/gen/type.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> --------- Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
@@ -527,41 +527,41 @@ type CityGroupBy struct {
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (cgb *CityGroupBy) Aggregate(fns ...AggregateFunc) *CityGroupBy {
|
||||
cgb.fns = append(cgb.fns, fns...)
|
||||
return cgb
|
||||
func (_g *CityGroupBy) Aggregate(fns ...AggregateFunc) *CityGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (cgb *CityGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, cgb.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := cgb.build.prepareQuery(ctx); err != nil {
|
||||
func (_g *CityGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CityQuery, *CityGroupBy](ctx, cgb.build, cgb, cgb.build.inters, v)
|
||||
return scanWithInterceptors[*CityQuery, *CityGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (cgb *CityGroupBy) sqlScan(ctx context.Context, root *CityQuery, v any) error {
|
||||
func (_g *CityGroupBy) sqlScan(ctx context.Context, root *CityQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(cgb.fns))
|
||||
for _, fn := range cgb.fns {
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*cgb.flds)+len(cgb.fns))
|
||||
for _, f := range *cgb.flds {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*cgb.flds...)...)
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := cgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
@@ -575,27 +575,27 @@ type CitySelect struct {
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (cs *CitySelect) Aggregate(fns ...AggregateFunc) *CitySelect {
|
||||
cs.fns = append(cs.fns, fns...)
|
||||
return cs
|
||||
func (_s *CitySelect) Aggregate(fns ...AggregateFunc) *CitySelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (cs *CitySelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, cs.ctx, ent.OpQuerySelect)
|
||||
if err := cs.prepareQuery(ctx); err != nil {
|
||||
func (_s *CitySelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CityQuery, *CitySelect](ctx, cs.CityQuery, cs, cs.inters, v)
|
||||
return scanWithInterceptors[*CityQuery, *CitySelect](ctx, _s.CityQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (cs *CitySelect) sqlScan(ctx context.Context, root *CityQuery, v any) error {
|
||||
func (_s *CitySelect) sqlScan(ctx context.Context, root *CityQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(cs.fns))
|
||||
for _, fn := range cs.fns {
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*cs.selector.flds); {
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
@@ -603,7 +603,7 @@ func (cs *CitySelect) sqlScan(ctx context.Context, root *CityQuery, v any) error
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := cs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
@@ -534,41 +534,41 @@ type StreetGroupBy struct {
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (sgb *StreetGroupBy) Aggregate(fns ...AggregateFunc) *StreetGroupBy {
|
||||
sgb.fns = append(sgb.fns, fns...)
|
||||
return sgb
|
||||
func (_g *StreetGroupBy) Aggregate(fns ...AggregateFunc) *StreetGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (sgb *StreetGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, sgb.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := sgb.build.prepareQuery(ctx); err != nil {
|
||||
func (_g *StreetGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*StreetQuery, *StreetGroupBy](ctx, sgb.build, sgb, sgb.build.inters, v)
|
||||
return scanWithInterceptors[*StreetQuery, *StreetGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (sgb *StreetGroupBy) sqlScan(ctx context.Context, root *StreetQuery, v any) error {
|
||||
func (_g *StreetGroupBy) sqlScan(ctx context.Context, root *StreetQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(sgb.fns))
|
||||
for _, fn := range sgb.fns {
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*sgb.flds)+len(sgb.fns))
|
||||
for _, f := range *sgb.flds {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*sgb.flds...)...)
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := sgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
@@ -582,27 +582,27 @@ type StreetSelect struct {
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ss *StreetSelect) Aggregate(fns ...AggregateFunc) *StreetSelect {
|
||||
ss.fns = append(ss.fns, fns...)
|
||||
return ss
|
||||
func (_s *StreetSelect) Aggregate(fns ...AggregateFunc) *StreetSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ss *StreetSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ss.ctx, ent.OpQuerySelect)
|
||||
if err := ss.prepareQuery(ctx); err != nil {
|
||||
func (_s *StreetSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*StreetQuery, *StreetSelect](ctx, ss.StreetQuery, ss, ss.inters, v)
|
||||
return scanWithInterceptors[*StreetQuery, *StreetSelect](ctx, _s.StreetQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (ss *StreetSelect) sqlScan(ctx context.Context, root *StreetQuery, v any) error {
|
||||
func (_s *StreetSelect) sqlScan(ctx context.Context, root *StreetQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ss.fns))
|
||||
for _, fn := range ss.fns {
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ss.selector.flds); {
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
@@ -610,7 +610,7 @@ func (ss *StreetSelect) sqlScan(ctx context.Context, root *StreetQuery, v any) e
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ss.driver.Query(ctx, query, args, rows); err != nil {
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
Reference in New Issue
Block a user