feat: add more and unify stats

Release-As: 0.16.1
This commit is contained in:
sentriz
2023-10-28 21:22:08 +01:00
committed by Senan Kelly
parent c1a34dc021
commit 2fdc1f41a2
5 changed files with 32 additions and 17 deletions

View File

@@ -80,6 +80,22 @@ func (db *DB) InsertBulkLeftMany(table string, head []string, left int, col []in
return db.Exec(q, values...).Error
}
type Stats struct {
Folders, Albums, Artists, AlbumArtists, Tracks, InternetRadioStations, Podcasts uint
}
func (db *DB) Stats() (Stats, error) {
var stats Stats
db.Model(Album{}).Count(&stats.Folders)
db.Model(AlbumArtist{}).Group("album_id").Count(&stats.Albums)
db.Model(TrackArtist{}).Group("artist_id").Count(&stats.Artists)
db.Model(AlbumArtist{}).Group("artist_id").Count(&stats.AlbumArtists)
db.Model(Track{}).Count(&stats.Tracks)
db.Model(InternetRadioStation{}).Count(&stats.InternetRadioStations)
db.Model(Podcast{}).Count(&stats.Podcasts)
return stats, nil
}
func (db *DB) GetUserByID(id int) *User {
var user User
err := db.