| 807 | } |
| 808 | |
| 809 | func (sps *StoragePolicySelect) sqlScan(ctx context.Context, root *StoragePolicyQuery, v any) error { |
| 810 | selector := root.sqlQuery(ctx) |
| 811 | aggregation := make([]string, 0, len(sps.fns)) |
| 812 | for _, fn := range sps.fns { |
| 813 | aggregation = append(aggregation, fn(selector)) |
| 814 | } |
| 815 | switch n := len(*sps.selector.flds); { |
| 816 | case n == 0 && len(aggregation) > 0: |
| 817 | selector.Select(aggregation...) |
| 818 | case n != 0 && len(aggregation) > 0: |
| 819 | selector.AppendSelect(aggregation...) |
| 820 | } |
| 821 | rows := &sql.Rows{} |
| 822 | query, args := selector.Query() |
| 823 | if err := sps.driver.Query(ctx, query, args, rows); err != nil { |
| 824 | return err |
| 825 | } |
| 826 | defer rows.Close() |
| 827 | return sql.ScanSlice(rows, v) |
| 828 | } |