File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -408,6 +408,25 @@ func (s *{{.StoreName}}) MustCount(q *{{.QueryName}}) int64 {
408
408
return s.Store.MustCount(q)
409
409
}
410
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
+
411
430
// FindOne returns the first row returned by the given query.
412
431
// `ErrNotFound` is returned if there are no results.
413
432
func (s *{{.StoreName}}) FindOne(q *{{.QueryName}}) (*{{.Name}}, error) {
You can’t perform that action at this time.
0 commit comments