{{/*
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.
*/}}

{{ define "dialect/sql/delete" }}
{{ $builder := pascal $.Scope.Builder }}
{{ $receiver := receiver $builder }}

func ({{ $receiver}} *{{ $builder }}) sqlExec(ctx context.Context) (int, error) {
	var (
		res sql.Result
		builder = sql.Dialect({{ $receiver }}.driver.Dialect())
	)
	selector := builder.Select().From(sql.Table({{ $.Package }}.Table))
	for _, p := range {{ $receiver }}.predicates {
		p(selector)
	}
	query, args := builder.Delete({{ $.Package }}.Table).FromSelect(selector).Query()
	if err := {{ $receiver }}.driver.Exec(ctx, query, args, &res); err != nil {
		return 0, err
	}
	affected, err := res.RowsAffected()
	if err != nil {
		return 0, err
	}
	return int(affected), nil
}

{{ end }}