{{/* Copyright 2019-present Facebook Inc. All rights reserved. This source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory of this source tree. */}} {{/* gotype: entgo.io/ent/entc/gen.typeScope */}} {{ define "dialect/sql/select" }} {{ $builder := pascal $.Scope.Builder }} {{ $receiver := $.Scope.Receiver }} func ({{ $receiver }} *{{ $builder }}) sqlScan(ctx context.Context, root *{{ $.QueryName }}, v any) error { selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len({{ $receiver}}.fns)) for _, fn := range {{ $receiver }}.fns { aggregation = append(aggregation, fn(selector)) } switch n := len(*{{ $receiver }}.selector.flds); { {{- /* If no columns were selected, the default selection is the aggregation.*/}} case n == 0 && len(aggregation) > 0: selector.Select(aggregation...) case n != 0 && len(aggregation) > 0: selector.AppendSelect(aggregation...) } rows := &sql.Rows{} query, args := selector.Query() if err := {{ $receiver }}.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } {{/* Allow adding methods to the select-builder by ent extensions or user templates.*/}} {{ with $tmpls := matchTemplate "dialect/sql/select/additional/*" }} {{- range $tmpl := $tmpls }} {{- xtemplate $tmpl $ }} {{- end }} {{ end }} {{ end }}