{{/*
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 := receiver $builder }}

func ({{ $receiver }} *{{ $builder }}) sqlScan(ctx context.Context, v interface{}) error {
	rows := &sql.Rows{}
	query, args := {{ $receiver }}.sql.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 }}
