// Code generated by cmd/gen/sqlc-wrapper. DO NOT EDIT.
package {{.PkgName}}

import (
	"context"
	"database/sql"
	"errors"

	"{{.RepoPkg}}"
)

// Store wraps *Queries and implements repository.Store.
type Store struct {
	q *Queries
}

// NewStore wraps a *Queries to satisfy repository.Store.
func NewStore(q *Queries) repository.Store {
	return &Store{q: q}
}

var errorMap = map[error]error{
	sql.ErrNoRows: repository.ErrNotFound,
}

func mapErr(err error) error {
	for from, to := range errorMap {
		if errors.Is(err, from) {
			return to
		}
	}
	return err
}

{{range .Methods}}{{.Signature}} {
{{.Body}}}

{{end}}

{{- define "void"}}	return mapErr({{.Call}})
{{end}}

{{- define "scalar"}}	r, err := {{.Call}}
	if err != nil {
		return {{.RepoType}}{}, mapErr(err)
	}
	return {{.RepoType}}(r), nil
{{end}}

{{- define "slice"}}	rows, err := {{.Call}}
	if err != nil {
		return nil, mapErr(err)
	}
	out := make([]{{.RepoType}}, len(rows))
	for i, row := range rows {
		out[i] = {{.RepoType}}(row)
	}
	return out, nil
{{end}}
