Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Exists" method for store #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions generator/templates/model.tgo
Expand Up @@ -408,6 +408,25 @@ func (s *{{.StoreName}}) MustCount(q *{{.QueryName}}) int64 {
return s.Store.MustCount(q)
}

// Exists returns true if there is at least one record by given query.
func (s *{{.StoreName}}) Exists(q *{{.QueryName}}) (bool, error) {
q.Limit(1)
q.Select(Schema.{{.Name}}.ID)
q.Offset(0)
rs, err := s.Find(q)
if err != nil {
return false, err
}

if !rs.Next() {
return false, nil
}

err = rs.Close()
return true, err
}


// FindOne returns the first row returned by the given query.
// `ErrNotFound` is returned if there are no results.
func (s *{{.StoreName}}) FindOne(q *{{.QueryName}}) (*{{.Name}}, error) {
Expand Down