photoprism/internal/query/moments_time.go
Michael Mayer c98ed8a125 Backend: Code clean-up #225
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-03-28 17:17:41 +01:00

25 lines
665 B
Go

package query
// MomentsTimeResult contains photo counts per month and year
type MomentsTimeResult struct {
PhotoYear int
PhotoMonth int
Count int
}
// GetMomentsTime counts photos per month and year
func (q *Query) GetMomentsTime() (results []MomentsTimeResult, err error) {
s := q.db.NewScope(nil).DB()
s = s.Table("photos").
Where("deleted_at IS NULL").
Select("photos.photo_year, photos.photo_month, COUNT(*) AS count").
Group("photos.photo_year, photos.photo_month").
Order("photos.photo_year DESC, photos.photo_month DESC")
if result := s.Scan(&results); result.Error != nil {
return results, result.Error
}
return results, nil
}