We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8048762 commit a43b681Copy full SHA for a43b681
generator/templates/model.tgo
@@ -408,6 +408,25 @@ func (s *{{.StoreName}}) MustCount(q *{{.QueryName}}) int64 {
408
return s.Store.MustCount(q)
409
}
410
411
+// Exists returns true if there is at least one record by given query.
412
+func (s *{{.StoreName}}) Exists(q *{{.QueryName}}) (bool, error) {
413
+ q.Limit(1)
414
+ q.Select(Schema.{{.Name}}.ID)
415
+ q.Offset(0)
416
+ rs, err := s.Find(q)
417
+ if err != nil {
418
+ return false, err
419
+ }
420
+
421
+ if !rs.Next() {
422
+ return false, nil
423
424
425
+ err = rs.Close()
426
+ return true, err
427
+}
428
429
430
// FindOne returns the first row returned by the given query.
431
// `ErrNotFound` is returned if there are no results.
432
func (s *{{.StoreName}}) FindOne(q *{{.QueryName}}) (*{{.Name}}, error) {
0 commit comments