mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +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:
@@ -599,41 +599,41 @@ type FileGroupBy struct {
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (fgb *FileGroupBy) Aggregate(fns ...AggregateFunc) *FileGroupBy {
|
||||
fgb.fns = append(fgb.fns, fns...)
|
||||
return fgb
|
||||
func (_g *FileGroupBy) Aggregate(fns ...AggregateFunc) *FileGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (fgb *FileGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, fgb.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := fgb.build.prepareQuery(ctx); err != nil {
|
||||
func (_g *FileGroupBy) 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[*FileQuery, *FileGroupBy](ctx, fgb.build, fgb, fgb.build.inters, v)
|
||||
return scanWithInterceptors[*FileQuery, *FileGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (fgb *FileGroupBy) sqlScan(ctx context.Context, root *FileQuery, v any) error {
|
||||
func (_g *FileGroupBy) sqlScan(ctx context.Context, root *FileQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(fgb.fns))
|
||||
for _, fn := range fgb.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(*fgb.flds)+len(fgb.fns))
|
||||
for _, f := range *fgb.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(*fgb.flds...)...)
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := fgb.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()
|
||||
@@ -647,27 +647,27 @@ type FileSelect struct {
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (fs *FileSelect) Aggregate(fns ...AggregateFunc) *FileSelect {
|
||||
fs.fns = append(fs.fns, fns...)
|
||||
return fs
|
||||
func (_s *FileSelect) Aggregate(fns ...AggregateFunc) *FileSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (fs *FileSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, fs.ctx, ent.OpQuerySelect)
|
||||
if err := fs.prepareQuery(ctx); err != nil {
|
||||
func (_s *FileSelect) 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[*FileQuery, *FileSelect](ctx, fs.FileQuery, fs, fs.inters, v)
|
||||
return scanWithInterceptors[*FileQuery, *FileSelect](ctx, _s.FileQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (fs *FileSelect) sqlScan(ctx context.Context, root *FileQuery, v any) error {
|
||||
func (_s *FileSelect) sqlScan(ctx context.Context, root *FileQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(fs.fns))
|
||||
for _, fn := range fs.fns {
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*fs.selector.flds); {
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
@@ -675,7 +675,7 @@ func (fs *FileSelect) sqlScan(ctx context.Context, root *FileQuery, v any) error
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := fs.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